Module: Trailblazer::Finder::Adapters::Sequel::Sorting

Defined in:
lib/trailblazer/finder/adapters/sequel/sorting.rb

Overview

ActiveRecord Paging Adapter

Class Method Summary collapse

Class Method Details

.set_sorting_handlerObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/trailblazer/finder/adapters/sequel/sorting.rb', line 12

def set_sorting_handler
  ->(sort_attributes, entity) do
    sort_attributes.delete(:handler)
    attributes = []
    sort_attributes.each do |attr|
      attributes << (::Sequel.send attr[1], attr[0].to_sym)
    end
    result = []
    result << [:order, attributes.first] if attributes.is_a? Array
    attributes.drop(1).each { |x| result << [:order_append, x] }
    result.reduce(entity) { |obj, method_and_args| obj.send(*method_and_args) }
  end
end