Class: ActiveSet::Filtering::Operation
- Inherits:
-
Object
- Object
- ActiveSet::Filtering::Operation
- Defined in:
- lib/active_set/filtering/operation.rb
Instance Method Summary collapse
-
#execute ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(set, instructions_hash) ⇒ Operation
constructor
A new instance of Operation.
-
#operation_instructions ⇒ Object
rubocop:enable Metrics/MethodLength.
Constructor Details
#initialize(set, instructions_hash) ⇒ Operation
Returns a new instance of Operation.
10 11 12 13 |
# File 'lib/active_set/filtering/operation.rb', line 10 def initialize(set, instructions_hash) @set = set @instructions_hash = instructions_hash end |
Instance Method Details
#execute ⇒ Object
rubocop:disable Metrics/MethodLength
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_set/filtering/operation.rb', line 16 def execute attribute_instructions = @instructions_hash .flatten_keys .map { |k, v| AttributeInstruction.new(k, v) } activerecord_filtered_set = attribute_instructions.reduce(@set) do |set, attribute_instruction| maybe_set_or_false = ActiveRecordStrategy.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 = EnumerableStrategy.new(set, attribute_instruction).execute next set unless maybe_set_or_false attribute_instruction.processed = true maybe_set_or_false end end |
#operation_instructions ⇒ Object
rubocop:enable Metrics/MethodLength
41 42 43 |
# File 'lib/active_set/filtering/operation.rb', line 41 def operation_instructions @instructions_hash.symbolize_keys end |