Class: DistributedStorage

Inherits:
Storage
  • Object
show all
Defined in:
lib/immutablebox.rb

Instance Method Summary collapse

Methods inherited from Storage

#get

Constructor Details

#initializeDistributedStorage

Returns a new instance of DistributedStorage.



286
287
288
# File 'lib/immutablebox.rb', line 286

def initialize
  @storages = []
end

Instance Method Details

#<<(storage) ⇒ Object



289
290
291
292
# File 'lib/immutablebox.rb', line 289

def <<(storage)
  @storages << storage
  self
end

#closeObject



296
297
298
# File 'lib/immutablebox.rb', line 296

def close
  @storages.each(&:close)
end

#openObject



293
294
295
# File 'lib/immutablebox.rb', line 293

def open
  @storages.each(&:open)
end

#put(piece_hash, piece) ⇒ Object



299
300
301
302
# File 'lib/immutablebox.rb', line 299

def put(piece_hash, piece)
  dice = piece_hash.unpack('L').first % @storages.size
  @storages[dice].put(piece_hash, piece)
end