Class: Faulty::Storage::AutoWire

Inherits:
Object
  • Object
show all
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

Class Method Details

.wrap(storage, **options) {|Options| ... } ⇒ Object

TODO:

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.

Parameters:

  • storage (Interface, Array<Interface>)

    A storage backed or array of storage backends to setup.

  • options (Hash)

    Attributes for Options

Yields:

  • (Options)

    For setting options in a block


55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/faulty/storage/auto_wire.rb', line 55

def wrap(storage, **options, &block)
  options = Options.new(options, &block)
  if storage.nil?
    Memory.new
  elsif storage.is_a?(Array)
    wrap_array(storage, options)
  elsif !storage.fault_tolerant?
    wrap_one(storage, options)
  else
    storage
  end
end