class Moneta::Adapter
Adapter
base class @api public
Attributes
backend[R]
Public Class Methods
backend(required: true, &block)
click to toggle source
Define a block used to build this adapter’s backend. The block will receive as keyword arguments any options passed to the adapter during initialization that are not config settings.
If the adapter is initialized with a ‘:backend` option, this will be used instead, and the block won’t be called.
@param [Boolean] required @yield [**options] options passed to the adapter’s initialize method @yieldreturn [Object] The backend to use
# File lib/moneta/adapter.rb, line 21 def backend(required: true, &block) raise "backend block already set" if class_variables(false).include?(:@@backend_block) class_variable_set(:@@backend_block, block) class_variable_set(:@@backend_required, true) if required end
backend_block()
click to toggle source
# File lib/moneta/adapter.rb, line 27 def backend_block class_variable_get(:@@backend_block) if class_variable_defined?(:@@backend_block) end
backend_required?()
click to toggle source
# File lib/moneta/adapter.rb, line 31 def backend_required? class_variable_defined?(:@@backend_required) end
new(options = {})
click to toggle source
@param [Hash] options
# File lib/moneta/adapter.rb, line 37 def initialize(options = {}) set_backend(**configure(**options)) end
Private Instance Methods
set_backend(backend: nil, **options)
click to toggle source
# File lib/moneta/adapter.rb, line 43 def set_backend(backend: nil, **options) @backend = backend || if backend_block = self.class.backend_block instance_exec(**options, &backend_block) end raise ArgumentError, 'backend needs to be set - refer to adapter documentation' if !@backend && self.class.backend_required? end