Class: SearchObject::Search
- Inherits:
-
Object
- Object
- SearchObject::Search
- Defined in:
- lib/search_object/search.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #count(context) ⇒ Object
-
#initialize(scope, params, actions) ⇒ Search
constructor
A new instance of Search.
- #param(name) ⇒ Object
- #query(context) ⇒ Object
Constructor Details
#initialize(scope, params, actions) ⇒ Search
Returns a new instance of Search.
5 6 7 8 9 |
# File 'lib/search_object/search.rb', line 5 def initialize(scope, params, actions) @scope = scope @actions = actions @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/search_object/search.rb', line 3 def params @params end |
Instance Method Details
#count(context) ⇒ Object
22 23 24 |
# File 'lib/search_object/search.rb', line 22 def count(context) query(context).count end |
#param(name) ⇒ Object
11 12 13 |
# File 'lib/search_object/search.rb', line 11 def param(name) @params[name] end |
#query(context) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/search_object/search.rb', line 15 def query(context) @params.inject(@scope) do |scope, (name, value)| new_scope = context.instance_exec scope, value, &@actions[name] new_scope || scope end end |