Class: Moneta::Proxy

Inherits:
Object
  • Object
show all
Includes:
Defaults
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 included from Defaults

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

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

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

Returns a new instance of Proxy.

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)



7
8
9
# File 'lib/moneta/proxy.rb', line 7

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: {})


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

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

#closeObject

Explicitly close the store

Returns:

  • nil



26
27
28
# File 'lib/moneta/proxy.rb', line 26

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



57
58
59
# File 'lib/moneta/proxy.rb', line 57

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

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

Note:

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

Atomically increment integer value with key

This method also accepts negative amounts.

Parameters:

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

Returns:

  • (Object)

    value from store



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

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)


16
17
18
# File 'lib/moneta/proxy.rb', line 16

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



36
37
38
# File 'lib/moneta/proxy.rb', line 36

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



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

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