Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/mongo_odm/core_ext/conversions.rb,
lib/mongo_odm/core_ext/hash_recursive_merge.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.type_cast(value) ⇒ Object
244 245 246 247 |
# File 'lib/mongo_odm/core_ext/conversions.rb', line 244 def self.type_cast(value) return nil if value.nil? Hash[value.to_hash.map{|k,v| [MongoODM.instanciate(k), MongoODM.instanciate(v)]}] end |
Instance Method Details
#dereference ⇒ Object
253 254 255 |
# File 'lib/mongo_odm/core_ext/conversions.rb', line 253 def dereference Hash[self.map{|k,v| [MongoODM.instanciate(MongoODM.dereference(k)), MongoODM.instanciate(MongoODM.dereference(v))]}] end |
#rmerge(other_hash) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/mongo_odm/core_ext/hash_recursive_merge.rb', line 8 def rmerge(other_hash) result = {} merge(other_hash) do |key, old_value, new_value| result[key] = old_value.class == self.class ? old_value.rmerge(new_value) : new_value end end |
#rmerge!(other_hash) ⇒ Object
2 3 4 5 6 |
# File 'lib/mongo_odm/core_ext/hash_recursive_merge.rb', line 2 def rmerge!(other_hash) merge!(other_hash) do |key, old_value, new_value| old_value.class == self.class ? old_value.rmerge!(new_value) : new_value end end |
#to_mongo ⇒ Object
249 250 251 |
# File 'lib/mongo_odm/core_ext/conversions.rb', line 249 def to_mongo Hash[self.map{|k,v| [k.to_mongo, v.to_mongo]}] end |