Class: Configatron::RootStore
- Inherits:
-
BasicObject
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/configatron/root_store.rb
Overview
This is the root configatron object, and contains methods which operate on the entire configatron hierarchy.
Constant Summary
collapse
- @@cow =
0
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of RootStore.
20
21
22
23
24
|
# File 'lib/configatron/root_store.rb', line 20
def initialize
@locked = false
@cow = nil
reset!
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
53
54
55
|
# File 'lib/configatron/root_store.rb', line 53
def method_missing(name, *args, &block)
store.__send__(name, *args, &block)
end
|
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
10
11
12
|
# File 'lib/configatron/root_store.rb', line 10
def store
@store
end
|
Instance Method Details
#__cow ⇒ Object
26
27
28
|
# File 'lib/configatron/root_store.rb', line 26
def __cow
@cow
end
|
#__cow_path(path) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/configatron/root_store.rb', line 30
def __cow_path(path)
start = @store.__cow_clone
node = start
branch = path.map do |key|
node = node[key]
node.__cow_clone
end
nodes = [start] + branch
nodes[0...-1].zip(nodes[1..-1], path) do |parent, child, key|
parent[key] = child
end
@store = nodes.first
nodes.last
end
|
#lock!(&blk) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/configatron/root_store.rb', line 91
def lock!(&blk)
if blk
orig = @locked
begin
@locked = true
blk.call
ensure
@locked = orig
end
else
@locked = true
end
end
|
#locked? ⇒ Boolean
87
88
89
|
# File 'lib/configatron/root_store.rb', line 87
def locked?
@locked
end
|
#reset! ⇒ Object
57
58
59
|
# File 'lib/configatron/root_store.rb', line 57
def reset!
@store = ::Configatron::Store.new(self)
end
|
#temp(&block) ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/configatron/root_store.rb', line 61
def temp(&block)
temp_start
begin
yield
ensure
temp_end
end
end
|
#temp_end ⇒ Object
80
81
82
83
84
85
|
# File 'lib/configatron/root_store.rb', line 80
def temp_end
@locked = @temp_locked
@cow = @temp_cow
@store = @temp
end
|
#temp_start ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/configatron/root_store.rb', line 71
def temp_start
@temp_locked = @locked
@temp_cow = @cow
@cow = @@cow += 1
@temp = @store
end
|
#unlock!(&blk) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/configatron/root_store.rb', line 105
def unlock!(&blk)
if blk
orig = @locked
begin
@locked = false
blk.call
ensure
@locked = orig
end
else
@locked = false
end
end
|