Class: Faulty::Storage::AutoWire
- Inherits:
-
Object
- Object
- Faulty::Storage::AutoWire
- Defined in:
- lib/faulty/storage/auto_wire.rb
Overview
Automatically configure a storage backend
Used by Faulty#initialize to setup sensible storage defaults
Defined Under Namespace
Classes: Options
Class Method Summary collapse
-
.wrap(storage, **options) {|Options| ... } ⇒ Object
Wrap storage backends with sensible defaults.
Class Method Details
.wrap(storage, **options) {|Options| ... } ⇒ Object
Consider using a FallbackChain for non-fault-tolerant storages by default. This would fallback to a Memory storage. It would require a more conservative implementation of Memory that could limit the number of circuits stored. For now, users need to manually configure fallbacks.
Wrap storage backends with sensible defaults
If the cache is nil
, create a new Memory storage.
If a single storage backend is given and is fault tolerant, leave it unmodified.
If a single storage backend is given and is not fault tolerant, wrap it in a CircuitProxy and a FaultTolerantProxy.
If an array of storage backends is given, wrap each non-fault-tolerant entry in a CircuitProxy and create a FallbackChain. If none of the backends in the array are fault tolerant, also wrap the FallbackChain in a FaultTolerantProxy.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/faulty/storage/auto_wire.rb', line 55 def wrap(storage, **, &block) = Options.new(, &block) if storage.nil? Memory.new elsif storage.is_a?(Array) wrap_array(storage, ) elsif !storage.fault_tolerant? wrap_one(storage, ) else storage end end |