Class: Cript::EHash
- Inherits:
-
Object
- Object
- Cript::EHash
- Defined in:
- lib/cript/ehash.rb
Overview
A hash backed by a Cript::Store object. All methods sent to an instance of this object are wrapped in a transaction and executed immediately.
Constant Summary collapse
- METHODS =
Hash.new.methods - Object.new.methods
- KEY =
:data
Instance Method Summary collapse
-
#initialize(file, options = {}) ⇒ EHash
constructor
A new instance of EHash.
- #inspect ⇒ Object
- #method_missing(sym, *args, &block) ⇒ Object
- #respond_to?(sym) ⇒ Boolean
Constructor Details
#initialize(file, options = {}) ⇒ EHash
Returns a new instance of EHash.
13 14 15 16 17 18 19 20 |
# File 'lib/cript/ehash.rb', line 13 def initialize(file, = {}) @store = Store.new(file, ) @store.transaction do unless @store[KEY].is_a?(Hash) @store[KEY] = {} end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/cript/ehash.rb', line 26 def method_missing(sym, *args, &block) super if !METHODS.include?(sym) || block_given? @store.transaction do @store[KEY].send(sym, *args) end end |
Instance Method Details
#inspect ⇒ Object
22 23 24 |
# File 'lib/cript/ehash.rb', line 22 def inspect "#<#{self.class.name} path='#{@store.path}'>" end |
#respond_to?(sym) ⇒ Boolean
34 35 36 |
# File 'lib/cript/ehash.rb', line 34 def respond_to?(sym) METHODS.include?(sym) end |