module Assorted::Scopes

Public Instance Methods

asc(column = sorting_column) click to toggle source
# File lib/assorted/scopes.rb, line 3
def asc(column = sorting_column)
  sanitized_order(column, :asc)
end
assorted(options) click to toggle source
# File lib/assorted/scopes.rb, line 11
def assorted(options)
  assorted_options.merge!(options)
end
desc(column = sorting_column) click to toggle source
# File lib/assorted/scopes.rb, line 7
def desc(column = sorting_column)
  sanitized_order(column, :desc)
end

Private Instance Methods

assorted_options() click to toggle source
# File lib/assorted/scopes.rb, line 29
def assorted_options
  @assorted_options ||= {}
end
sanitized_order(column, direction) click to toggle source
# File lib/assorted/scopes.rb, line 17
def sanitized_order(column, direction)
  if attribute_names.include?(column.to_s)
    order("#{table_name}.#{column} #{direction}")
  else
    raise ActiveRecord::StatementInvalid, "Unknown column #{column}"
  end
end
sorting_column() click to toggle source
# File lib/assorted/scopes.rb, line 25
def sorting_column
  assorted_options[:default_sort_column] || Assorted.options[:default_sort_column]
end