Class: Blobby::CompositeStore
- Inherits:
-
Object
- Object
- Blobby::CompositeStore
- 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
- #[](key) ⇒ Object
- #available? ⇒ Boolean
-
#initialize(stores) ⇒ CompositeStore
constructor
A new instance of CompositeStore.
Constructor Details
#initialize(stores) ⇒ CompositeStore
Returns a new instance of CompositeStore.
9 10 11 |
# File 'lib/blobby/composite_store.rb', line 9 def initialize(stores) @stores = stores end |
Instance Method Details
#[](key) ⇒ Object
13 14 15 16 17 |
# File 'lib/blobby/composite_store.rb', line 13 def [](key) KeyConstraint.must_allow!(key) objects = stores.map { |store| store[key] } StoredObject.new(objects) end |
#available? ⇒ Boolean
19 20 21 |
# File 'lib/blobby/composite_store.rb', line 19 def available? stores.all?(&:available?) end |