Class: Cript::EHash
- Inherits:
-
Object
show all
- 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
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(file, opts = {}) ⇒ 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, opts = {})
@store = Store.new(file, opts)
@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
30
31
32
33
34
35
36
|
# File 'lib/cript/ehash.rb', line 30
def method_missing(sym, *args, &block)
super if !METHODS.include?(sym) || block_given?
@store.transaction do
@store[KEY].send(sym, *args)
end
end
|
Class Method Details
.insecure(file, opts = {}) ⇒ Object
22
23
24
|
# File 'lib/cript/ehash.rb', line 22
def self.insecure(file, opts = {})
new(file, opts.merge({ private_key_content: INSECURE_PRIVATE_KEY }))
end
|
Instance Method Details
#inspect ⇒ Object
26
27
28
|
# File 'lib/cript/ehash.rb', line 26
def inspect
"#<#{self.class.name} path='#{@store.path}'>"
end
|
#respond_to_missing?(sym, include_private = false) ⇒ Boolean
38
39
40
|
# File 'lib/cript/ehash.rb', line 38
def respond_to_missing?(sym, include_private = false)
METHODS.include?(sym) || super
end
|