Module: Searchgasm::Search::Conditions
- Defined in:
- lib/searchgasm/search/conditions.rb
Overview
Searchgasm Conditions
Implements all of the conditions functionality into a searchgasm search. All of this functonality is extracted out into its own class Searchgasm::Conditions::Base. This is a separate module to help keep the code clean and organized.
Class Method Summary collapse
Instance Method Summary collapse
-
#conditions_with_conditions=(values) ⇒ Object
Sets conditions on the search.
- #initialize_with_conditions(init_options = {}) ⇒ Object
-
#sanitize_with_conditions(searching = true) ⇒ Object
:nodoc:.
Class Method Details
.included(klass) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/searchgasm/search/conditions.rb', line 8 def self.included(klass) klass.class_eval do alias_method_chain :initialize, :conditions alias_method_chain :conditions=, :conditions alias_method_chain :sanitize, :conditions end end |
Instance Method Details
#conditions_with_conditions=(values) ⇒ Object
Sets conditions on the search. Accepts a hash or a Searchgasm::Conditions::Base object.
Examples
search.conditions = {:first_name_like => "Ben"}
search.conditions = User.new_conditions
or to set a scope
search.conditions = "user_group_id = 6"
now you can create the rest of your search and your “scope” will get merged into your final SQL. What this does is determine if the value a hash or a conditions object, if not it sets it up as a scope.
34 35 36 37 38 39 40 41 |
# File 'lib/searchgasm/search/conditions.rb', line 34 def conditions_with_conditions=(values) case values when Searchgasm::Conditions::Base @conditions = values else @conditions.conditions = values end end |
#initialize_with_conditions(init_options = {}) ⇒ Object
16 17 18 19 |
# File 'lib/searchgasm/search/conditions.rb', line 16 def initialize_with_conditions( = {}) self.conditions = Searchgasm::Conditions::Base.create_virtual_class(klass).new initialize_without_conditions() end |
#sanitize_with_conditions(searching = true) ⇒ Object
:nodoc:
43 44 45 46 47 48 49 50 |
# File 'lib/searchgasm/search/conditions.rb', line 43 def sanitize_with_conditions(searching = true) # :nodoc: = sanitize_without_conditions(searching) if conditions_obj = .delete(:conditions) new_conditions = conditions_obj.sanitize [:conditions] = new_conditions unless new_conditions.blank? end end |