Class: Moneta::Adapter

Inherits:
Object
  • Object
show all
Includes:
Config, Defaults
Defined in:
lib/moneta/adapter.rb

Overview

Adapter base class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Config

#config, included

Methods included from Defaults

#[], #[]=, #close, #create, #decrement, #each_key, #features, #fetch, #fetch_values, included, #increment, #key?, #merge!, #slice, #supports?, #update, #values_at

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}) ⇒ Adapter

Returns a new instance of Adapter.

Parameters:

  • options (Hash) (defaults to: {})


37
38
39
# File 'lib/moneta/adapter.rb', line 37

def initialize(options = {})
  set_backend(**configure(**options))
end

Instance Attribute Details

#backendObject (readonly)



8
9
10
# File 'lib/moneta/adapter.rb', line 8

def backend
  @backend
end

Class Method Details

.backend(required: true) {|**options| ... } ⇒ Object

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.

Parameters:

  • required (Boolean) (defaults to: true)

Yields:

  • (**options)

    options passed to the adapter’s initialize method

Yield Returns:

  • (Object)

    The backend to use



21
22
23
24
25
# 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_blockObject



27
28
29
# File 'lib/moneta/adapter.rb', line 27

def backend_block
  class_variable_get(:@@backend_block) if class_variable_defined?(:@@backend_block)
end

.backend_required?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/moneta/adapter.rb', line 31

def backend_required?
  class_variable_defined?(:@@backend_required)
end