Class: Moneta::Enumerable

Inherits:
Proxy
  • Object
show all
Includes:
Enumerable
Defined in:
lib/moneta/enumerable.rb

Overview

Adds the Ruby Enumerable API to the store. The underlying store must support `:each_key`.

Examples:

Adding to a builder

Moneta.build do
  # It should be the top middleware
  use :Enumerable
  adapter :DBM
end

Instance Attribute Summary

Attributes inherited from Proxy

#adapter

Instance Method Summary collapse

Methods inherited from Proxy

#clear, #close, #create, #delete, #each_key, #features, features_mask, #fetch_values, #increment, #key?, #load, #merge!, not_supports, #slice, #store, #values_at

Methods included from Defaults

#[], #[]=, #close, #create, #decrement, #each_key, #features, #fetch, #fetch_values, included, #increment, #key?, #merge!, #slice, #supports?, #update, #values_at

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

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

Returns a new instance of Enumerable.


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

def initialize(adapter, options = {})
  raise "Adapter must support :each_key" unless adapter.supports? :each_key
  super
end

Instance Method Details

#eachEnumerator #each {|pair| ... } ⇒ self Also known as: each_pair

Enumerate over all pairs in the store

Overloads:

  • #eachEnumerator

    Returns:

    • (Enumerator)
  • #each {|pair| ... } ⇒ self

    Yield Parameters:

    • pair (Array<(Object, Object)>)

      Each pair is yielded

    Returns:

    • (self)

30
31
32
33
34
# File 'lib/moneta/enumerable.rb', line 30

def each
  return enum_for(:each) unless block_given?
  each_key { |key| yield key, load(key) }
  self
end