Module: GoodSort::Sorter

Defined in:
lib/good_sort/sorter.rb

Instance Method Summary collapse

Instance Method Details

#sort_by(p) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/good_sort/sorter.rb', line 4

def sort_by(p)
  return unless p && p[:field] && p[:down]
  f = p[:field]
  unless options = sort_fields[f.to_sym]
    raise ArgumentError, "Requested field #{f} was not defined in #{class_name} for sorting"
  end
  options = options.dup
  options[:order] += ' DESC' unless p[:down].blank?
  options
end

#sort_fieldsObject



3
# File 'lib/good_sort/sorter.rb', line 3

def sort_fields; @@sort_fields ||= {}; end