Class: ActiveSet::Sorting::ActiveRecordStrategy
- Inherits:
-
Object
- Object
- ActiveSet::Sorting::ActiveRecordStrategy
- Defined in:
- lib/active_set/sorting/active_record_strategy.rb
Instance Method Summary collapse
- #executable_instructions ⇒ Object
- #execute ⇒ Object
-
#initialize(set, attribute_instructions) ⇒ ActiveRecordStrategy
constructor
A new instance of ActiveRecordStrategy.
Constructor Details
#initialize(set, attribute_instructions) ⇒ ActiveRecordStrategy
Returns a new instance of ActiveRecordStrategy.
8 9 10 11 12 13 14 |
# File 'lib/active_set/sorting/active_record_strategy.rb', line 8 def initialize(set, attribute_instructions) @set = set @attribute_instructions = attribute_instructions @set_instructions = attribute_instructions.map do |attribute_instruction| ActiveRecordSetInstruction.new(attribute_instruction, set) end end |
Instance Method Details
#executable_instructions ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/active_set/sorting/active_record_strategy.rb', line 28 def executable_instructions return {} unless @set.respond_to? :to_sql @set_instructions.select do |set_instruction| attribute_model = set_instruction.attribute_model next false unless attribute_model next false unless attribute_model.respond_to?(:attribute_names) next false unless attribute_model.attribute_names.include?(set_instruction.attribute) true end end |
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_set/sorting/active_record_strategy.rb', line 16 def execute return false unless @set.respond_to? :to_sql executable_instructions.reduce(@set) do |set, set_instruction| statement = set.merge(set_instruction.initial_relation) statement = statement.merge(order_operation_for(set_instruction)) set_instruction.processed = true statement end end |