Sha256: 254cb666f9891c1b71345fcd2e0737f2422af85e3be79bfccffafb566aa206e0
Contents?: true
Size: 1.07 KB
Versions: 14
Compression:
Stored size: 1.07 KB
Contents
module MongoModel module Attributes module Mongo def to_mongo inject({}) do |result, (k, v)| property = properties[k] if property result[property.as] = property.to_mongo(v) else converter = Types.converter_for(v.class) result[k.to_s] = converter.to_mongo(v) end result end end def load!(hash) from_mongo!(hash) changed.clear end def from_mongo!(hash) hash.each do |k, v| property = properties_as[k.to_s] if property child = self[property.name] = property.from_mongo(v) child.parent_document = instance if child.respond_to?(:parent_document=) else self[k.to_sym] = v end end end private def properties_as @properties_as ||= properties.inject({}) do |result, (name, property)| result[property.as] = property result end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems