Module: ScopedSearch::ClassMethods
- Defined in:
- lib/scoped_search.rb
Overview
The ClassMethods module will be included into the ActiveRecord::Base class to add the ActiveRecord::Base.scoped_search method and the ActiveRecord::Base.search_for named scope.
Class Method Summary collapse
Instance Method Summary collapse
-
#scoped_search(*definitions) ⇒ Object
Export the scoped_search method fo defining the search options.
Class Method Details
.extended(base) ⇒ Object
21 22 23 24 |
# File 'lib/scoped_search.rb', line 21 def self.extended(base) super base.class_attribute :scoped_search_definition end |
Instance Method Details
#scoped_search(*definitions) ⇒ Object
Export the scoped_search method fo defining the search options. This method will create a definition instance for the class if it does not yet exist, or if a parent definition exists then it will create a new one inheriting it, and use the object as block argument and return value.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/scoped_search.rb', line 30 def scoped_search(*definitions) self.scoped_search_definition ||= ScopedSearch::Definition.new(self) unless self.scoped_search_definition.klass == self # inheriting the parent self.scoped_search_definition = ScopedSearch::Definition.new(self) end definitions.each do |definition| if definition[:on].kind_of?(Array) definition[:on].each { |field| self.scoped_search_definition.define(**definition.merge(:on => field)) } else self.scoped_search_definition.define(**definition) end end return self.scoped_search_definition end |