Parent

Class/Module Index [+]

Quicksearch

Mongoid::Criterion::Selector

The selector is a hash-like object that has special behaviour for merging mongoid criteria selectors.

Attributes

fields[R]
klass[R]

Public Instance Methods

[]=(key, value) click to toggle source

Set the value for the supplied key, attempting to typecast the value.

@example Set the value for the key.

selector["$ne"] = { :name => "Zorg" }

@param [ String, Symbol ] key The hash key. @param [ Object ] value The value to set.

@since 2.0.0

# File lib/mongoid/criterion/selector.rb, line 31
def []=(key, value)
  key = "#{key}.#{::I18n.locale}" if klass.fields[key.to_s].try(:localized?)
  super(key, try_to_typecast(key, value))
end
inspect() click to toggle source

Generate pretty inspection for old ruby versions.

@example Inspect the selector.

selector.inspect

@return [ String ] The inspected selector.

# File lib/mongoid/criterion/selector.rb, line 63
def inspect
  ret = self.keys.inject([]) do |ret, key|
    ret << "#{key.inspect}=>#{self[key].inspect}"
  end
  "{#{ret.sort.join(', ')}}"
end
merge!(other) click to toggle source

Merge the selector with another hash.

@example Merge the objects.

selector.merge!({ :key => "value" })

@param [ Hash, Selector ] other The object to merge with.

@return [ Selector ] The merged selector.

@since 1.0.0

# File lib/mongoid/criterion/selector.rb, line 46
def merge!(other)
  tap do |selector|
    other.each_pair do |key, value|
      selector[key] = value
    end
  end
end
Also aliased as: update
update(other) click to toggle source
Alias for: merge!

Public Class Methods

new(klass) click to toggle source

Create the new selector.

@example Create the selector.

Selector.new(Person)

@param [ Class ] klass The class the selector is for.

@since 1.0.0

# File lib/mongoid/criterion/selector.rb, line 18
def initialize(klass)
  @fields, @klass = klass.fields.except("_id", "_type"), klass
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.