Included Modules

Files

Class/Module Index [+]

Quicksearch

Moneta::Defaults

Simple interface to key/value stores with Hash-like interface. @api public

Public Class Methods

included(base) click to toggle source
# File lib/moneta/mixins.rb, line 81
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

[](key) click to toggle source

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

@param [Object] key @return [Object] value @api public

# File lib/moneta/mixins.rb, line 177
def [](key)
  load(key)
end
[]=(key, value) click to toggle source

Store value with key

@param [Object] key @param [Object] value @return value @api public

# File lib/moneta/mixins.rb, line 187
def []=(key, value)
  store(key, value)
end
close() click to toggle source

Explicitly close the store @return nil @api public

# File lib/moneta/mixins.rb, line 135
def close
end
create(key, value, options = {}) click to toggle source

Atomically sets a key to value if it's not set.

@note Not every Moneta store implements this method,

a NotImplementedError is raised if it is not supported.

@param [Object] key @param [Object] value @param [Hash] options @option options [Integer] :expires Update expiration time (See {Expires}) @option options [Boolean] :raw Raw access without value transformation (See {Transformer}) @option options [String] :prefix Prefix key (See {Transformer}) @return [Boolean] key was set @api public

# File lib/moneta/mixins.rb, line 203
def create(key, value, options = {})
  raise NotImplementedError, 'create is not supported'
end
decrement(key, amount = 1, options = {}) click to toggle source

Atomically decrement integer value with key

This is just syntactic sugar for calling increment with a negative value.

This method also accepts negative amounts.

@param [Object] key @param [Integer] amount @param [Hash] options @option options [String] :prefix Prefix key (See {Transformer}) @option options Other options as defined by the adapters or middleware @return [Object] value from store @api public

# File lib/moneta/mixins.rb, line 128
def decrement(key, amount = 1, options = {})
  increment(key, -amount, options)
end
features() click to toggle source

Returns features list

@return [Array<Symbol>] list of features

# File lib/moneta/mixins.rb, line 210
def features
  self.class.features
end
fetch(key, default = nil, options = nil) click to toggle source

Fetch a value with a key

@overload fetch(key, options = {}, &block)

retrieve a key. if the key is not available, execute the
block and return its return value.
@param [Object] key
@param [Hash] options
@option options [Integer] :expires Update expiration time (See {Expires})
@option options [Boolean] :raw Raw access without value transformation (See {Transformer})
@option options [String] :prefix Prefix key (See {Transformer})
@return [Object] value from store

@overload fetch(key, default, options = {})

retrieve a key. if the key is not available, return the default value.
@param [Object] key
@param [Object] default Default value
@param [Hash] options
@option options [Integer] :expires Update expiration time (See {Expires})
@option options [Boolean] :raw Raw access without value transformation (See {Transformer})
@option options [String] :prefix Prefix key (See {Transformer})
@return [Object] value from store

@api public

# File lib/moneta/mixins.rb, line 161
def fetch(key, default = nil, options = nil)
  if block_given?
    raise ArgumentError, 'Only one argument accepted if block is given' if options
    result = load(key, default || {})
    result == nil ? yield(key) : result
  else
    result = load(key, options || {})
    result == nil ? default : result
  end
end
increment(key, amount = 1, options = {}) click to toggle source

Atomically increment integer value with key

This method also accepts negative amounts.

@note Not every Moneta store implements this method,

a NotImplementedError is raised if it is not supported.

@param [Object] key @param [Integer] amount @param [Hash] options @option options [String] :prefix Prefix key (See {Transformer}) @option options Other options as defined by the adapters or middleware @return [Object] value from store @api public

# File lib/moneta/mixins.rb, line 111
def increment(key, amount = 1, options = {})
  raise NotImplementedError, 'increment is not supported'
end
key?(key, options = {}) click to toggle source

Exists the value with key

@param [Object] key @param [Hash] options @option options [Integer] :expires Update expiration time (See {Expires}) @option options [String] :prefix Prefix key (See {Transformer}) @option options Other options as defined by the adapters or middleware @return [Boolean] @api public

# File lib/moneta/mixins.rb, line 94
def key?(key, options = {})
  load(key, options) != nil
end
supports?(feature) click to toggle source

Return true if adapter supports the given feature.

@return [Boolean]

# File lib/moneta/mixins.rb, line 217
def supports?(feature)
  features.include?(feature)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.