Methods

Files

Class/Module Index [+]

Quicksearch

Moneta::OptionMerger

@api private

Constants

METHODS

Attributes

default_options[R]

Public Class Methods

new(adapter, options = {}) click to toggle source

@param [Moneta store] adapter underlying adapter @param [Hash] options

# 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

Protected Instance Methods

wrap(method, *args) click to toggle source
# File lib/moneta/optionmerger.rb, line 36
def wrap(method, *args)
  options = args.last
  options.merge!(@default_options[method]) if Hash === options && @default_options.include?(method)
  yield
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.