module Mongoid::Criteria::Queryable::Extensions::Hash
This module contains additional hash behavior.
Public Instance Methods
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 22 def __add__(object) apply_strategy(:__add__, object) end
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 36 def __add_from_array__(array) { keys.first => array.__add__(values.first) } end
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 118 def __deep_copy__ {}.tap do |copy| each_pair do |key, value| copy.store(key, value.__deep_copy__) end end end
Make a deep copy of this hash.
@example Make a deep copy of the hash.
{ field: value }.__deep_copy__
@return [ Hash ] The copied hash.
@since 1.0.0
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 150 def __expand_complex__ replacement = {} each_pair do |key, value| replacement.merge!(key.__expr_part__(value.__expand_complex__)) end replacement end
Get the object as expanded.
@example Get the object expanded.
obj.__expand_complex__
@return [ Hash ] The expanded hash.
@since 1.0.5
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 50 def __intersect__(object) apply_strategy(:__intersect__, object) end
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 64 def __intersect_from_array__(array) { keys.first => array.__intersect__(values.first) } end
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 78 def __intersect_from_object__(object) { keys.first => object.__intersect__(values.first) } end
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 134 def __sort_option__ tap do |hash| hash.each_pair do |key, value| hash.store(key, value.to_direction) end end end
Get the hash as a sort option.
@example Get the hash as a sort option.
{ field: 1 }.__sort_option__
@return [ Hash ] The hash as sort option.
@since 1.0.0
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 92 def __union__(object) apply_strategy(:__union__, object) end
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 106 def __union_from_object__(object) { keys.first => object.__union__(values.first) } end
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 168 def update_values(&block) each_pair do |key, value| store(key, block[value]) end end
Update all the values in the hash with the provided block.
@example Update the values in place.
{ field: "1" }.update_values(&:to_i)
@param [ Proc ] block The block to execute on each value.
@return [ Hash ] the hash.
@since 1.0.0
Private Instance Methods
Source
# File lib/mongoid/criteria/queryable/extensions/hash.rb, line 189 def apply_strategy(strategy, object) tap do |hash| object.each_pair do |key, value| hash.store(key, hash[key].send(strategy, value)) end end end