Class: Mongoid::Criterion::Complex
- 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.
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#operator ⇒ Object
Returns the value of attribute operator.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Is the criterion equal to the other?.
-
#eql?(other) ⇒ true, false
Is the criterion equal to the other?.
-
#hash ⇒ Hash
Get the criterion as a hash.
-
#initialize(opts = {}) ⇒ Complex
constructor
Create the new complex criterion.
-
#to_mongo_query(v) ⇒ Hash
Create a mongo query with given value.
-
#to_s ⇒ String
Returns the name of the key as a string.
Constructor Details
#initialize(opts = {}) ⇒ Complex
Create the new complex criterion.
21 22 23 |
# File 'lib/mongoid/criterion/complex.rb', line 21 def initialize(opts = {}) @key, @operator = opts[:key], opts[:operator] end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
13 14 15 |
# File 'lib/mongoid/criterion/complex.rb', line 13 def key @key end |
#operator ⇒ Object
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) ⇒ true, false
Is the criterion equal to the other?
66 67 68 69 |
# File 'lib/mongoid/criterion/complex.rb', line 66 def ==(other) return false unless other.is_a?(self.class) self.key == other.key && self.operator == other.operator end |
#eql?(other) ⇒ true, false
Is the criterion equal to the other?
54 55 56 |
# File 'lib/mongoid/criterion/complex.rb', line 54 def eql?(other) self == (other) end |
#hash ⇒ Hash
Get the criterion as a hash.
31 32 33 |
# File 'lib/mongoid/criterion/complex.rb', line 31 def hash [@key, @operator].hash end |
#to_mongo_query(v) ⇒ Hash
Create a mongo query with given value
42 43 44 |
# File 'lib/mongoid/criterion/complex.rb', line 42 def to_mongo_query(v) {"$#{self.operator}" => v} end |
#to_s ⇒ String
Returns the name of the key as a string.
79 80 81 |
# File 'lib/mongoid/criterion/complex.rb', line 79 def to_s key.to_s end |