class Configatron::RootStore
This is the root configatron object, and contains methods which operate on the entire configatron hierarchy.
Attributes
store[R]
Public Class Methods
new()
click to toggle source
# File lib/configatron/root_store.rb, line 20 def initialize @locked = false @cow = nil reset! end
Public Instance Methods
__cow()
click to toggle source
# File lib/configatron/root_store.rb, line 26 def __cow @cow end
__cow_path(path)
click to toggle source
# 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 # [node1, node2, node3] with # [node2, node3, node4] and # ['key1', 'key2, 'key3'] nodes[0...-1].zip(nodes[1..-1], path) do |parent, child, key| # These are all cow_clones, so won't trigger a further cow # modification. parent[key] = child end @store = nodes.first nodes.last end
lock!(&blk)
click to toggle source
# 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?()
click to toggle source
# File lib/configatron/root_store.rb, line 87 def locked? @locked end
method_missing(name, *args, &block)
click to toggle source
# File lib/configatron/root_store.rb, line 53 def method_missing(name, *args, &block) store.__send__(name, *args, &block) end
reset!()
click to toggle source
# File lib/configatron/root_store.rb, line 57 def reset! @store = ::Configatron::Store.new(self) end
temp() { || ... }
click to toggle source
# File lib/configatron/root_store.rb, line 61 def temp(&block) temp_start begin yield ensure temp_end end end
temp_end()
click to toggle source
# File lib/configatron/root_store.rb, line 80 def temp_end @locked = @temp_locked @cow = @temp_cow @store = @temp end
temp_start()
click to toggle source
# File lib/configatron/root_store.rb, line 71 def temp_start @temp_locked = @locked @temp_cow = @cow # Just need to have a unique Copy-on-Write generation ID @cow = @@cow += 1 @temp = @store end
unlock!(&blk)
click to toggle source
# 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