Class: Argumenta::Storage::DHT

Inherits:
Object
  • Object
show all
Defined in:
lib/argumenta/storage/dht.rb

Overview

A DHT data store for Argumenta objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DHT

Returns a new instance of DHT.



9
10
11
# File 'lib/argumenta/storage/dht.rb', line 9

def initialize(options = {})
  @hash = ::DHT::Hash.new options
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



7
8
9
# File 'lib/argumenta/storage/dht.rb', line 7

def hash
  @hash
end

Instance Method Details

#add_proposition(proposition) ⇒ Object



13
14
15
16
17
# File 'lib/argumenta/storage/dht.rb', line 13

def add_proposition(proposition)
  Argumenta::Proposition.validate proposition
  sha1 = proposition.sha1()
  @hash[sha1] = proposition.text
end

#get_proposition(sha1) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/argumenta/storage/dht.rb', line 19

def get_proposition(sha1)
  text = @hash[sha1]
  unless text
    raise RetrievalError, "No proposition found for '#{sha1}'."
  end
  proposition = Argumenta::Proposition.new text
end