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