Sha256: 07ef13190ade21c29711f9feac48247467a77dd46f34c79f895f5edd55758f37
Contents?: true
Size: 636 Bytes
Versions: 1
Compression:
Stored size: 636 Bytes
Contents
module DataMapper module Resource # Converts a Resource to a JSON representation. def to_couch_json(dirty = false) property_list = self.class.properties.select { |key, value| dirty ? self.dirty_attributes.key?(key) : true } data = {} for property in property_list do data[property.field] = if property.type.respond_to?(:dump) property.type.dump(property.get!(self), property) else property.get!(self) end end data.delete('_attachments') if data['_attachments'].nil? || data['_attachments'].empty? data.to_json end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dm-couchdb-adapter-0.10.2 | lib/couchdb_adapter/resource.rb |