Complex criterion are used when performing operations on symbols to get get a shorthand syntax for where clauses.
@example Conversion of a simple to complex criterion.
{ :field => { "$lt" => "value" } } becomes: { :field.lt => "value }
Is the criterion equal to the other?
@example Check equality.
criterion == other
@param [ Complex ] other The other complex criterion.
@return [ true, false ] If they are equal.
# File lib/mongoid/criterion/complex.rb, line 65 def ==(other) return false unless other.is_a?(self.class) self.key == other.key && self.operator == other.operator end
Is the criterion equal to the other?
@example Check equality.
criterion.eql?(other)
@param [ Complex ] other The other complex criterion.
@return [ true, false ] If they are equal.
# File lib/mongoid/criterion/complex.rb, line 53 def eql?(other) self == (other) end
Get the criterion as a hash.
@example Get the criterion as a hash.
criterion.hash
@return [ Hash ] The keys and operators.
# File lib/mongoid/criterion/complex.rb, line 30 def hash [@key, @operator].hash end
Create a mongo query with given value
@example Create query
criterion.to_mongo_hash(value)
@params [] Whatever is a valid input for given operator @return [ Hash ] The query
# File lib/mongoid/criterion/complex.rb, line 41 def to_mongo_query(v) {"$#{self.operator}" => v} end
Returns the name of the key as a string.
@example Get the name of the key.
criterion.to_s
@return [ String ] The field name.
@since 2.1.0
# File lib/mongoid/criterion/complex.rb, line 78 def to_s key.to_s end
Create the new complex criterion.
@example Instantiate a new complex criterion.
Complex.new(:key => :field, :operator => "$gt")
@param [ Hash ] opts The options to convert.
# File lib/mongoid/criterion/complex.rb, line 20 def initialize(opts = {}) @key, @operator = opts[:key], opts[:operator] end
Generated with the Darkfish Rdoc Generator 2.