Parent

Class/Module Index [+]

Quicksearch

Mongoid::Criterion::Complex

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 }

Attributes

key[RW]
operator[RW]

Public Instance Methods

==(other) click to toggle source

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
eql?(other) click to toggle source

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
hash() click to toggle source

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
to_mongo_query(v) click to toggle source

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
to_s() click to toggle source

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

Public Class Methods

new(opts = {}) click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.