class ActiveSet::Filtering::Operation

Public Class Methods

new(set, instructions_hash) click to toggle source
# File lib/active_set/filtering/operation.rb, line 10
def initialize(set, instructions_hash)
  @set = set
  @instructions_hash = instructions_hash
end

Public Instance Methods

execute() click to toggle source
# File lib/active_set/filtering/operation.rb, line 15
def execute
  attribute_instructions = flatten_keys_of(@instructions_hash)
                           .map { |k, v| AttributeInstruction.new(k, v) }

  activerecord_filtered_set = attribute_instructions.reduce(@set) do |set, attribute_instruction|
    maybe_set_or_false = ActiveRecord::Strategy.new(set, attribute_instruction).execute
    next set unless maybe_set_or_false

    attribute_instruction.processed = true
    maybe_set_or_false
  end

  return activerecord_filtered_set if attribute_instructions.all?(&:processed?)

  attribute_instructions.reject(&:processed?).reduce(activerecord_filtered_set) do |set, attribute_instruction|
    maybe_set_or_false = Enumerable::Strategy.new(set, attribute_instruction).execute
    next set unless maybe_set_or_false

    attribute_instruction.processed = true
    maybe_set_or_false
  end
end
operation_instructions() click to toggle source
# File lib/active_set/filtering/operation.rb, line 38
def operation_instructions
  @instructions_hash.symbolize_keys
end