module FetcheableOnApi::Sortable::ClassMethods

Class methods made available to your controllers.

Public Instance Methods

sort_by(*attrs) click to toggle source

Define one ore more sortable attribute configurations.

@param attrs [Array] options to define one or more sorting

configurations.

@option attrs [String, nil] :as Alias the sorted attribute @option attrs [true, false, nil] :with Wether to sort on the lowercase

attribute value.
# 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