Module: DataMapper::Resource
- Defined in:
- lib/couchdb_adapter/resource.rb
Instance Method Summary collapse
-
#to_couch_json(dirty = false) ⇒ Object
Converts a Resource to a JSON representation.
Instance Method Details
#to_couch_json(dirty = false) ⇒ Object
Converts a Resource to a JSON representation.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/couchdb_adapter/resource.rb', line 4 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 |