Class: Hanami::Settings::CompositeStore
- Inherits:
-
Object
- Object
- Hanami::Settings::CompositeStore
- Defined in:
- lib/hanami/settings/composite_store.rb
Overview
A settings store that chains multiple stores with fallback resolution.
Each store is tried in order. The first store to return a value wins. Stores must implement ‘#fetch` with the same signature as `Hash#fetch`.
Constant Summary collapse
- Undefined =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Dry::Core::Constants::Undefined
Instance Method Summary collapse
-
#fetch(name, *args) {|name| ... } ⇒ Object
Fetches a value by trying each store in order.
-
#initialize(*stores) ⇒ CompositeStore
constructor
A new instance of CompositeStore.
Constructor Details
#initialize(*stores) ⇒ CompositeStore
Returns a new instance of CompositeStore.
26 27 28 |
# File 'lib/hanami/settings/composite_store.rb', line 26 def initialize(*stores) @stores = stores end |
Instance Method Details
#fetch(name, *args) {|name| ... } ⇒ Object
Fetches a value by trying each store in order.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hanami/settings/composite_store.rb', line 40 def fetch(name, *args, &block) @stores.each do |store| value = store.fetch(name, Undefined) return value unless value.equal?(Undefined) end return args.first unless args.empty? return yield(name) if block raise KeyError, "key not found: #{name.inspect}" end |