lib/dolly/collection.rb in dolly-0.4.0 vs lib/dolly/collection.rb in dolly-0.5.0
- old
+ new
@@ -1,7 +1,5 @@
-require 'dolly/representations/collection_representation'
-
module Dolly
class Collection
extend Forwardable
attr_accessor :rows
attr_writer :json, :docs_class
@@ -42,23 +40,33 @@
def count
load if empty?
length
end
+ def rows= ary
+ ary.each do |r|
+ next unless r['doc']
+ properties = r['doc']
+ id = properties.delete '_id'
+ rev = properties.delete '_rev' if properties['_rev']
+ document = docs_class.new properties
+ document.doc = properties.merge({'_id' => id, '_rev' => rev})
+ @set << document
+ end
+ @rows = ary
+ end
+
def load
- @set = self.extend(representation).from_json(json).rows
+ parsed = JSON::parse json
+ self.rows = parsed['rows']
end
def to_json options = {}
load if empty?
map{|r| r.doc }.to_json(options)
end
private
- def representation
- Representations::CollectionRepresentation.config(docs_class)
- end
-
def docs_class
@docs_class
end
def json