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:, options: nil, defaults: nil, params: nil) ⇒ Search

Returns a new instance of 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
  @options = options || {}
  @defaults = defaults || {}

  self.params = params
end

Instance Attribute Details

#paramsObject

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, &@options[name]
    new_scope || scope
  end
end