lib/eternity/index.rb in eternity-0.0.5 vs lib/eternity/index.rb in eternity-0.1.0
- old
+ new
@@ -1,11 +1,14 @@
module Eternity
class Index < Restruct::NestedHash.new(CollectionIndex)
- def initialize
- super redis: Eternity.redis,
- id: Eternity.keyspace[:index][SecureRandom.uuid]
+ attr_reader :name
+
+ def initialize(name=nil)
+ @name = name ? name.to_s : SecureRandom.uuid
+ super connection: Eternity.connection,
+ id: Eternity.keyspace[:index][@name]
end
def apply(delta)
delta.each do |collection, elements|
elements.each do |id, change|
@@ -21,9 +24,17 @@
def self.read_blob(sha1)
Index.new.tap do |index|
index.restore Blob.read :index, sha1
end
+ end
+
+ def self.all
+ sections_count = Eternity.keyspace[:index].sections.count
+ names = Eternity.connection.call('KEYS', Eternity.keyspace[:index]['*']).map do |key|
+ Restruct::Id.new(key).sections[sections_count]
+ end.uniq
+ names.map { |name| new name }
end
end
end
\ No newline at end of file