Class: Moneta::Adapters::Memory

Inherits:
Object
  • Object
show all
Includes:
CreateSupport, Defaults, HashAdapter, IncrementSupport
Defined in:
lib/moneta/adapters/memory.rb

Overview

Memory backend using a hash to store the entries

Direct Known Subclasses

Cookie, DBM, Daybreak, GDBM, KyotoCabinet, LevelDB, SDBM, TDB, TokyoCabinet

Instance Attribute Summary

Attributes included from HashAdapter

#backend

Instance Method Summary collapse

Methods included from CreateSupport

#create, included

Methods included from IncrementSupport

included, #increment

Methods included from HashAdapter

#clear, #delete, #key?, #load, #store

Methods included from Defaults

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

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}) ⇒ Memory

Returns a new instance of Memory

Options Hash (options):

  • :backend (Hash)

    Use existing backend instance


15
16
17
# File 'lib/moneta/adapters/memory.rb', line 15

def initialize(options = {})
  @backend = options[:backend] || {}
end

Instance Method Details

#each_key(&block) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/moneta/adapters/memory.rb', line 19

def each_key(&block)
  return enum_for(:each_key) unless block_given?

  if @backend.respond_to?(:each_key)
    @backend.each_key(&block)
  elsif @backend.respond_to?(:keys)
    if keys = @backend.keys
      keys.each(&block)
    end
  elsif @backend.respond_to?(:each)
    @backend.each { |k| yield(k) }
  else
    raise ::NotImplementedError, "No enumerator found on backend"
  end

  self
end