Class: MongoModel::MongoOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/mongomodel/support/mongo_operator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, operator) ⇒ MongoOperator

Returns a new instance of MongoOperator.



5
6
7
# File 'lib/mongomodel/support/mongo_operator.rb', line 5

def initialize(field, operator)
  @field, @operator = field, operator
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



3
4
5
# File 'lib/mongomodel/support/mongo_operator.rb', line 3

def field
  @field
end

#operatorObject (readonly)

Returns the value of attribute operator.



3
4
5
# File 'lib/mongomodel/support/mongo_operator.rb', line 3

def operator
  @operator
end

Instance Method Details

#==(other) ⇒ Object



17
18
19
# File 'lib/mongomodel/support/mongo_operator.rb', line 17

def ==(other)
  other.is_a?(self.class) && field == other.field && operator == other.operator
end

#eql?(other) ⇒ Boolean

Returns:



25
26
27
# File 'lib/mongomodel/support/mongo_operator.rb', line 25

def eql?(other)
  self == other
end

#hashObject



21
22
23
# File 'lib/mongomodel/support/mongo_operator.rb', line 21

def hash
  field.hash ^ operator.hash
end

#inspectObject



13
14
15
# File 'lib/mongomodel/support/mongo_operator.rb', line 13

def inspect
  "#{field.inspect}.#{operator}"
end

#to_mongo_selector(value) ⇒ Object



9
10
11
# File 'lib/mongomodel/support/mongo_operator.rb', line 9

def to_mongo_selector(value)
  { "$#{operator}" => value }
end