Class: ActiveSet::Sorting::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/active_set/sorting/operation.rb

Instance Method Summary collapse

Constructor Details

#initialize(set, instructions_hash) ⇒ Operation

Returns a new instance of Operation.



10
11
12
13
# File 'lib/active_set/sorting/operation.rb', line 10

def initialize(set, instructions_hash)
  @set = set
  @instructions_hash = instructions_hash
end

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_set/sorting/operation.rb', line 15

def execute
  attribute_instructions = flatten_keys_of(@instructions_hash)
                           .map { |k, v| AttributeInstruction.new(k, v) }

  activerecord_strategy = ActiveRecordStrategy.new(@set, attribute_instructions)
  if activerecord_strategy.executable_instructions == attribute_instructions
    activerecord_sorted_set = activerecord_strategy.execute
  end

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

  EnumerableStrategy.new(@set, attribute_instructions).execute
end

#operation_instructionsObject



29
30
31
# File 'lib/active_set/sorting/operation.rb', line 29

def operation_instructions
  @instructions_hash.symbolize_keys
end