Module: FetcheableOnApi::Sortable::ClassMethods

Defined in:
lib/fetcheable_on_api/sortable.rb

Overview

Class methods made available to your controllers.

Instance Method Summary collapse

Instance Method Details

#sort_by(*attrs) ⇒ Object

Define one ore more sortable attribute configurations.

Parameters:

  • attrs (Array)

    options to define one or more sorting configurations.

Options Hash (*attrs):

  • :as (String, nil)

    Alias the sorted attribute

  • :with (true, false, nil)

    Wether to sort on the lowercase attribute value.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fetcheable_on_api/sortable.rb', line 34

def sort_by(*attrs)
  options = attrs.extract_options!
  options.symbolize_keys!

  self.sorts_configuration = sorts_configuration.dup

  attrs.each do |attr|
    sorts_configuration[attr] ||= {
      as: attr,
    }

    sorts_configuration[attr] = sorts_configuration[attr].merge(options)
  end
end