Class: Eternity::Index
- Inherits:
-
Object
- Object
- Eternity::Index
- Defined in:
- lib/eternity/index.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #apply(delta) ⇒ Object
-
#initialize(name = nil) ⇒ Index
constructor
A new instance of Index.
- #write_blob ⇒ Object
Constructor Details
#initialize(name = nil) ⇒ Index
Returns a new instance of Index.
6 7 8 9 10 |
# File 'lib/eternity/index.rb', line 6 def initialize(name=nil) @name = name ? name.to_s : SecureRandom.uuid super connection: Eternity.connection, id: Eternity.keyspace[:index][@name] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/eternity/index.rb', line 4 def name @name end |
Class Method Details
.all ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/eternity/index.rb', line 31 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 |
.read_blob(sha1) ⇒ Object
25 26 27 28 29 |
# File 'lib/eternity/index.rb', line 25 def self.read_blob(sha1) Index.new.tap do |index| index.restore Blob.read :index, sha1 end end |
Instance Method Details
#apply(delta) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/eternity/index.rb', line 12 def apply(delta) delta.each do |collection, elements| elements.each do |id, change| args = [id, change['data']].compact self[collection].send change['action'], *args end end end |
#write_blob ⇒ Object
21 22 23 |
# File 'lib/eternity/index.rb', line 21 def write_blob Blob.write :index, dump end |