Module: Moneta::OptionSupport Private

Included in:
Defaults
Defined in:
lib/moneta/mixins.rb

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

Instance Method Summary collapse

Instance Method Details

#expires(expires) ⇒ OptionMerger

Return Moneta store with default expiration time

Parameters:

  • expires (Integer)

    Default expiration time

Returns:


47
48
49
# File 'lib/moneta/mixins.rb', line 47

def expires(expires)
  with(:expires => expires, :only => [:store, :increment])
end

#prefix(prefix) ⇒ OptionMerger

Return Moneta store with default prefix option

Parameters:

  • prefix (String)

    Key prefix

Returns:


38
39
40
# File 'lib/moneta/mixins.rb', line 38

def prefix(prefix)
  with(:prefix => prefix, :except => :clear)
end

#rawOptionMerger

Return Moneta store with default option :raw => true

Returns:


24
25
26
27
28
29
30
31
# File 'lib/moneta/mixins.rb', line 24

def raw
  @raw_store ||=
    begin
      store = with(:raw => true, :only => [:load, :store, :delete])
      store.instance_variable_set(:@raw_store, store)
      store
    end
end

#with(options = nil, &block) ⇒ Moneta store

Return Moneta store with default options or additional proxies

Parameters:

  • options (Hash) (defaults to: nil)

    Options to merge

Returns:


10
11
12
13
14
15
16
17
18
# File 'lib/moneta/mixins.rb', line 10

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