Class: Blobby::CompositeStore

Inherits:
Object
  • Object
show all
Defined in:
lib/blobby/composite_store.rb

Overview

Compose a number of stores.

Writes go to all stores. Reads use the first store to respond.

Defined Under Namespace

Classes: StoredObject

Instance Method Summary collapse

Constructor Details

#initialize(stores) ⇒ CompositeStore

Returns a new instance of CompositeStore.



11
12
13
# File 'lib/blobby/composite_store.rb', line 11

def initialize(stores)
  @stores = stores
end

Instance Method Details

#[](key) ⇒ Object



15
16
17
18
19
# File 'lib/blobby/composite_store.rb', line 15

def [](key)
  KeyConstraint.must_allow!(key)
  objects = stores.map { |store| store[key] }
  StoredObject.new(objects)
end

#available?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/blobby/composite_store.rb', line 21

def available?
  stores.all?(&:available?)
end