The selector is a hash-like object that has special behaviour for merging mongoid criteria selectors.
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
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 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
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
Generated with the Darkfish Rdoc Generator 2.