Class: Eternity::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/eternity/index.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/eternity/index.rb', line 4

def name
  @name
end

Class Method Details

.allObject



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_blobObject



21
22
23
# File 'lib/eternity/index.rb', line 21

def write_blob
  Blob.write :index, dump
end