lib/ruote/storage/hash_storage.rb in ruote-2.1.10 vs lib/ruote/storage/hash_storage.rb in ruote-2.1.11

- old
+ new

@@ -55,11 +55,10 @@ synchronize do pre = get(doc['type'], doc['_id']) - #if pre && ( ! opts[:update_rev]) && pre['_rev'] != doc['_rev'] if pre && pre['_rev'] != doc['_rev'] return pre end if pre.nil? && doc['_rev'] @@ -120,28 +119,40 @@ # NOTE : no dup here for now synchronize do - docs = key ? - @h[type].values.select { |doc| doc['_id'].match(key) } : + keys = key ? + Array(key).map { |k| k.is_a?(String) ? "!#{k}" : k } : nil + + docs = keys ? + @h[type].values.select { |doc| + Ruote::StorageBase.key_match?(keys, doc) + } : @h[type].values - if l = opts[:limit] - docs[0, l] - else - docs - end + docs = docs.sort_by { |d| d['_id'] } + + return docs.size if opts[:count] + + docs = docs.reverse if opts[:descending] + + skip = opts[:skip] || 0 + limit = opts[:limit] || docs.size + + docs[skip, limit] end end # Returns a sorted list of all the ids for a given type. # def ids (type) @h[type].keys.sort end + # Purges the storage completely. + # def purge! @h = %w[ variables