1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
module Moneta
# @api private
module OptionSupport
# Return Moneta store with default options or additional proxies
#
# @param [Hash] options Options to merge
# @return [Moneta store]
#
# @api public
def with(options = nil, &block)
adapter = self
if block
builder = Builder.new(&block)
builder.adapter(adapter)
adapter = builder.build.last
end
options ? OptionMerger.new(adapter, options) : adapter
end
# Return Moneta store with default option raw: true
#
# @return [OptionMerger]
# @api public
def raw
@raw ||=
begin
store = with(raw: true, only: [:load, :store, :create, :delete])
store.instance_variable_set(:@raw, store)
store
end
end
# Return Moneta store with default prefix option
#
# @param [String] prefix Key prefix
# @return [OptionMerger]
# @api public
def prefix(prefix)
with(prefix: prefix, except: :clear)
end
# Return Moneta store with default expiration time
#
# @param [Integer] expires Default expiration time
# @return [OptionMerger]
# @api public
def expires(expires)
with(expires: expires, only: [:store, :create, :increment])
end
end
end
|