Module: MongoMapper::Extensions::Hash::ClassMethods
- Defined in:
- lib/mongo_mapper/extensions/hash.rb
Instance Method Summary collapse
Instance Method Details
#from_mongo(value) ⇒ Object
31 32 33 |
# File 'lib/mongo_mapper/extensions/hash.rb', line 31 def from_mongo(value) HashWithIndifferentAccess.new(value || {}) end |
#to_mongo(value, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mongo_mapper/extensions/hash.rb', line 10 def to_mongo(value, = {}) stringify_bson = [:stringify_bson] recursive = [:recursive] value = value.clone if recursive hash = value.to_hash hash.each do |k,v| case v when Document, EmbeddedDocument, Hash, Array, Set v = v.to_mongo() if v and recursive when BSON::ObjectId, BSON::Binary v = v.to_s if stringify_bson end hash[k] = v end hash end |