Class: MongoSearch::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo-search/definition.rb

Instance Method Summary collapse

Constructor Details

#initialize {|Builder.new(self)| ... } ⇒ Definition

Returns a new instance of Definition.

Yields:



3
4
5
6
7
# File 'lib/mongo-search/definition.rb', line 3

def initialize
  @filters = []
  @sorter  = nil
  yield Builder.new(self) if block_given?
end

Instance Method Details

#<<(filter) ⇒ Object



9
10
11
# File 'lib/mongo-search/definition.rb', line 9

def <<(filter)
  @filters << filter
end

#criteria_for(params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mongo-search/definition.rb', line 17

def criteria_for(params)
  conditions = {}

  @filters.each do |filter|
    conditions.merge! filter.call(params)
  end

  sort = @sorter ? @sorter.call(params) : []

  [conditions, sort]
end

#sorter=(sorter) ⇒ Object



13
14
15
# File 'lib/mongo-search/definition.rb', line 13

def sorter=(sorter)
  @sorter = sorter
end