Class: Moneta::Proxy

Inherits:
Base
  • Object
show all
Defined in:
lib/moneta/proxy.rb

Overview

Proxy base class

Direct Known Subclasses

Expires, Transformer, Wrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #decrement, #fetch

Methods included from Mixins::WithOptions

#expires, #prefix, #raw, #with

Constructor Details

#initialize(adapter, options = {}) ⇒ Proxy

Constructor

Parameters:

  • adapter (Moneta store)

    underlying adapter

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

11
12
13
# File 'lib/moneta/proxy.rb', line 11

def initialize(adapter, options = {})
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)


5
6
7
# File 'lib/moneta/proxy.rb', line 5

def adapter
  @adapter
end

Instance Method Details

#clear(options = {}) ⇒ void

This method returns an undefined value.

Clear all keys in this store

Parameters:

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

75
76
77
78
# File 'lib/moneta/proxy.rb', line 75

def clear(options = {})
  @adapter.clear(options)
  self
end

#closeObject

Close this store

Returns:

  • nil


83
84
85
# File 'lib/moneta/proxy.rb', line 83

def close
  @adapter.close
end

#delete(key, options = {}) ⇒ Object

Delete the key from the store and return the current value

Parameters:

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

Returns:

  • (Object)

    current value


52
53
54
# File 'lib/moneta/proxy.rb', line 52

def delete(key, options = {})
  @adapter.delete(key, options)
end

#increment(key, amount = 1, options = {}) ⇒ Object

Atomically increment integer value with key

Not every Moneta store implements this method, a NotImplementedError if it is not supported.

Parameters:

  • key (Object)
  • amount (Integer) (defaults to: 1)
  • options (Hash) (defaults to: {})

Returns:

  • (Object)

    value from store


66
67
68
# File 'lib/moneta/proxy.rb', line 66

def increment(key, amount = 1, options = {})
  @adapter.increment(key, amount, options)
end

#key?(key, options = {}) ⇒ Boolean

Exists the value with key

Parameters:

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

Returns:

  • (Boolean)

21
22
23
# File 'lib/moneta/proxy.rb', line 21

def key?(key, options = {})
  @adapter.key?(key, options)
end

#load(key, options = {}) ⇒ Object

Fetch value with key. Return nil if the key doesn't exist

Parameters:

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

Returns:

  • (Object)

    value


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

def load(key, options = {})
  @adapter.load(key, options)
end

#store(key, value, options = {}) ⇒ Object

Store value with key

Parameters:

  • key (Object)
  • value (Object)
  • options (Hash) (defaults to: {})

Returns:

  • value


42
43
44
# File 'lib/moneta/proxy.rb', line 42

def store(key, value, options = {})
  @adapter.store(key, value, options)
end