Class: Moneta::WeakEachKey
- Defined in:
- lib/moneta/weak_each_key.rb
Overview
This class wraps methods that store and retrieve entries in order to track which keys are in the store, and uses this list when doing key traversal. This means that each_key will only yield keys which have been accessed previously via the present store object. This wrapper is therefore best suited to adapters which are not persistent, and which cannot be shared.
Adds weak key enumeration support to the underlying store
Instance Attribute Summary
Attributes inherited from Proxy
Instance Method Summary collapse
-
#each_key ⇒ Object
Calls block once for each key in store, passing the key as a parameter.
-
#initialize(adapter, options = {}) ⇒ WeakEachKey
constructor
A new instance of WeakEachKey.
Methods inherited from Wrapper
#clear, #close, #config, #create, #delete, #features, #fetch_values, #increment, #key?, #load, #merge!, #slice, #store, #values_at
Methods inherited from Proxy
#clear, #close, #config, #create, #delete, #features, features_mask, #fetch_values, #increment, #key?, #load, #merge!, not_supports, #slice, #store, #values_at
Methods included from Config
Methods included from Defaults
#[], #[]=, #close, #create, #decrement, #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 = {}) ⇒ WeakEachKey
Returns a new instance of WeakEachKey.
19 20 21 22 23 |
# File 'lib/moneta/weak_each_key.rb', line 19 def initialize(adapter, = {}) raise 'Store already supports feature :each_key' if adapter.supports?(:each_key) @all_keys = Set.new super end |
Instance Method Details
#each_key ⇒ Enumerator #each_key {|key| ... } ⇒ self
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Calls block once for each key in store, passing the key as a parameter. If no block is given, an enumerator is returned instead.
26 27 28 29 30 |
# File 'lib/moneta/weak_each_key.rb', line 26 def each_key return enum_for(:each_key) { all_keys.size } unless block_given? all_keys.each { |key| yield key } self end |