Class: SearchObject::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/search_object/search.rb

Overview

:api: private

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, params, actions) ⇒ Search

Returns a new instance of Search.



6
7
8
9
10
# File 'lib/search_object/search.rb', line 6

def initialize(scope, params, actions)
  @scope    = scope
  @actions  = actions
  @params   = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/search_object/search.rb', line 4

def params
  @params
end

Instance Method Details

#count(context) ⇒ Object



23
24
25
# File 'lib/search_object/search.rb', line 23

def count(context)
  query(context).count
end

#param(name) ⇒ Object



12
13
14
# File 'lib/search_object/search.rb', line 12

def param(name)
  @params[name]
end

#query(context) ⇒ Object



16
17
18
19
20
21
# File 'lib/search_object/search.rb', line 16

def query(context)
  @params.inject(@scope) do |scope, (name, value)|
    new_scope = context.instance_exec scope, value, &@actions[name]
    new_scope || scope
  end
end