Class: SearchObject::Search
- Inherits:
-
Object
- Object
- SearchObject::Search
- Defined in:
- lib/search_object/search.rb
Overview
:api: private
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #count(context) ⇒ Object
-
#initialize(scope:, options: nil, defaults: nil, params: nil) ⇒ Search
constructor
A new instance of Search.
- #param(name) ⇒ Object
- #query(context) ⇒ Object
Constructor Details
#initialize(scope:, options: nil, defaults: nil, params: nil) ⇒ Search
8 9 10 11 12 13 14 |
# File 'lib/search_object/search.rb', line 8 def initialize(scope:, options: nil, defaults: nil, params: nil) @scope = scope = || {} @defaults = defaults || {} self.params = params end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'lib/search_object/search.rb', line 6 def params @params end |
Instance Method Details
#count(context) ⇒ Object
31 32 33 |
# File 'lib/search_object/search.rb', line 31 def count(context) query(context).count end |
#param(name) ⇒ Object
20 21 22 |
# File 'lib/search_object/search.rb', line 20 def param(name) @params[name.to_s] end |
#query(context) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/search_object/search.rb', line 24 def query(context) @params.inject(@scope) do |scope, (name, value)| new_scope = context.instance_exec scope, value, &[name] new_scope || scope end end |