Class: DHT::Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/dht/hash.rb,
lib/dht/version.rb

Constant Summary collapse

VERSION =
'0.0.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Hash

Returns a new instance of Hash.



7
8
9
10
# File 'lib/dht/hash.rb', line 7

def initialize(options = {})
  @node = DHT::Node.new(options)
  @node.start
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



5
6
7
# File 'lib/dht/hash.rb', line 5

def node
  @node
end

Instance Method Details

#[](key) ⇒ Object



36
37
38
# File 'lib/dht/hash.rb', line 36

def [](key)
  get(key)
end

#[]=(key, value) ⇒ Object



32
33
34
# File 'lib/dht/hash.rb', line 32

def []=(key, value)
  store(key, value)
end

#get(key) ⇒ Object



28
29
30
# File 'lib/dht/hash.rb', line 28

def get(key)
  manager.storage_for(key).get(key)
end

#managerObject



20
21
22
# File 'lib/dht/hash.rb', line 20

def manager
  me[:manager]
end

#meObject



12
13
14
# File 'lib/dht/hash.rb', line 12

def me
  DCell.me
end

#storageObject



16
17
18
# File 'lib/dht/hash.rb', line 16

def storage
  me[:storage]
end

#store(key, value) ⇒ Object



24
25
26
# File 'lib/dht/hash.rb', line 24

def store(key, value)
  manager.storage_for(key).store(key, value)
end