Class: Mongoid::Criterion::Complex

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/criterion/complex.rb

Overview

Complex criterion are used when performing operations on symbols to get get a shorthand syntax for where clauses.

Example:

{ :field => { "$lt" => "value" } } becomes: { :field.lt => "value }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Complex

Create the new complex criterion.



16
17
18
# File 'lib/mongoid/criterion/complex.rb', line 16

def initialize(opts = {})
  @key, @operator = opts[:key], opts[:operator]
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



13
14
15
# File 'lib/mongoid/criterion/complex.rb', line 13

def key
  @key
end

#operatorObject

Returns the value of attribute operator.



13
14
15
# File 'lib/mongoid/criterion/complex.rb', line 13

def operator
  @operator
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
31
# File 'lib/mongoid/criterion/complex.rb', line 28

def ==(other)
  return false unless other.is_a?(self.class)
  self.key == other.key && self.operator == other.operator
end

#eql?(other) ⇒ Boolean

Returns:



24
25
26
# File 'lib/mongoid/criterion/complex.rb', line 24

def eql?(other)
  self == (other)
end

#hashObject



20
21
22
# File 'lib/mongoid/criterion/complex.rb', line 20

def hash
  [@key, @operator].hash
end