module ScopedSearch::ClassMethods
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.
Public Class Methods
extended(base)
click to toggle source
Calls superclass method
# File lib/scoped_search.rb 20 def self.extended(base) 21 super 22 base.class_attribute :scoped_search_definition 23 end
Public Instance Methods
scoped_search(*definitions)
click to toggle source
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.
# File lib/scoped_search.rb 29 def scoped_search(*definitions) 30 self.scoped_search_definition ||= ScopedSearch::Definition.new(self) 31 unless self.scoped_search_definition.klass == self # inheriting the parent 32 self.scoped_search_definition = ScopedSearch::Definition.new(self) 33 end 34 35 definitions.each do |definition| 36 if definition[:on].kind_of?(Array) 37 definition[:on].each { |field| self.scoped_search_definition.define(definition.merge(:on => field)) } 38 else 39 self.scoped_search_definition.define(definition) 40 end 41 end 42 return self.scoped_search_definition 43 end