Module: ScopedSearch::Model::ClassMethods

Defined in:
lib/scoped_search.rb

Instance Method Summary collapse

Instance Method Details

#scoped_order(*columns_names) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/scoped_search.rb', line 103

def scoped_order(*columns_names)
  if defined?(Mongoid) && self.include?(Mongoid::Document)
    columns_names.each do |column_name|
      scope :"ascend_by_#{column_name}",  order_by([column_name.to_sym, :asc])
      scope :"descend_by_#{column_name}", order_by([column_name.to_sym, :desc])
    end
  else
    columns_names.each do |column_name|
      scope :"ascend_by_#{column_name}",  order("#{column_name} asc")
      scope :"descend_by_#{column_name}", order("#{column_name} desc")
    end
  end
end

#scoped_search(options = {}) ⇒ Object



99
100
101
# File 'lib/scoped_search.rb', line 99

def scoped_search(options={})
  ScopedSearch::Base.new(self, options.present? ? options : {})
end