Module: Faulty::ImmutableOptions
- Included in:
- Cache::AutoWire::Options, Cache::CircuitProxy::Options, Cache::FaultTolerantProxy::Options, Circuit::Options, Options, Status, Storage::AutoWire::Options, Storage::CircuitProxy::Options, Storage::FallbackChain::Options, Storage::FaultTolerantProxy::Options, Storage::Memory::Options, Storage::Redis::Options
- Defined in:
- lib/faulty/immutable_options.rb
Overview
A struct that cannot be modified after initialization
Instance Method Summary collapse
-
#defaults ⇒ Hash<Symbol, Object>
A hash of default values to set before yielding to the block.
- #dup_with(hash, &block) ⇒ Object
-
#finalize ⇒ void
Runs before freezing to finalize attribute initialization.
- #initialize(hash) {|self| ... } ⇒ Object
-
#required ⇒ Array<Symbol>
An array of required attributes.
- #setup(hash) {|_self| ... } ⇒ Object
Instance Method Details
#defaults ⇒ Hash<Symbol, Object>
A hash of default values to set before yielding to the block
28 29 30 |
# File 'lib/faulty/immutable_options.rb', line 28 def defaults {} end |
#dup_with(hash, &block) ⇒ Object
12 13 14 |
# File 'lib/faulty/immutable_options.rb', line 12 def dup_with(hash, &block) dup.setup(hash, &block) end |
#finalize ⇒ void
This method returns an undefined value.
Runs before freezing to finalize attribute initialization
42 43 |
# File 'lib/faulty/immutable_options.rb', line 42 def finalize end |
#initialize(hash) {|self| ... } ⇒ Object
8 9 10 |
# File 'lib/faulty/immutable_options.rb', line 8 def initialize(hash, &block) setup(defaults.merge(hash), &block) end |
#required ⇒ Array<Symbol>
An array of required attributes
35 36 37 |
# File 'lib/faulty/immutable_options.rb', line 35 def required [] end |
#setup(hash) {|_self| ... } ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/faulty/immutable_options.rb', line 16 def setup(hash) hash&.each { |key, value| self[key] = value } yield self if block_given? finalize guard_required! freeze self end |