Class: Moneta::OptionMerger Private

Inherits:
Wrapper show all
Defined in:
lib/moneta/optionmerger.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

METHODS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[:key?, :load, :store, :create, :delete, :increment, :clear].freeze

Instance Attribute Summary collapse

Attributes inherited from Proxy

#adapter

Instance Method Summary collapse

Methods inherited from Wrapper

#clear, #close, #create, #delete, #each_key, #features, #fetch_values, #increment, #key?, #load, #merge!, #slice, #store, #values_at

Methods inherited from Proxy

#clear, #close, #create, #delete, #each_key, #features, features_mask, #fetch_values, #increment, #key?, #load, #merge!, not_supports, #slice, #store, #values_at

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(adapter, options = {}) ⇒ OptionMerger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of OptionMerger

Parameters:

  • adapter (Moneta store)

    underlying adapter

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

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/moneta/optionmerger.rb', line 10

def initialize(adapter, options = {})
  super(adapter, options)

  @default_options = adapter.respond_to?(:default_options) ? adapter.default_options.dup : {}

  if options.include?(:only)
    raise ArgumentError, 'Either :only or :except is allowed' if options.include?(:except)
    methods = [options.delete(:only)].compact.flatten
  elsif options.include?(:except)
    methods = METHODS - [options.delete(:except)].compact.flatten
  else
    methods = METHODS
  end

  methods.each do |method|
    if oldopts = @default_options[method]
      newopts = (@default_options[method] = oldopts.merge(options))
      newopts[:prefix] = "#{oldopts[:prefix]}#{options[:prefix]}" if oldopts[:prefix] || options[:prefix]
    else
      @default_options[method] = options
    end
  end
end

Instance Attribute Details

#default_optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


6
7
8
# File 'lib/moneta/optionmerger.rb', line 6

def default_options
  @default_options
end