class Astrails::Safe::Config::Node
Attributes
data[R]
parent[R]
Public Class Methods
new(parent = nil, data = {}, &block)
click to toggle source
# File lib/astrails/safe/config/node.rb, line 8 def initialize(parent = nil, data = {}, &block) @parent = parent @data = {} merge data, &block end
Public Instance Methods
dump(indent = "")
click to toggle source
# File lib/astrails/safe/config/node.rb, line 59 def dump(indent = "") @data.each do |key, value| if value.is_a?(Node) puts "#{indent}#{key}:" value.dump(indent + " ") else puts "#{indent}#{key}: #{value.inspect}" end end end
each(&block)
click to toggle source
# File lib/astrails/safe/config/node.rb, line 46 def each(&block) @data.each(&block) end
find(*path)
click to toggle source
recursive find starts at the node and continues to the parent
# File lib/astrails/safe/config/node.rb, line 31 def find(*path) get(*path) || @parent && @parent.find(*path) end
Also aliased as: []
get(*path)
click to toggle source
looks for the path from this node DOWN. will not delegate to parent
# File lib/astrails/safe/config/node.rb, line 21 def get(*path) key = path.shift value = @data[key.to_s] return value if (nil != value) && path.empty? value && value.get(*path) end
merge(data = {})
click to toggle source
# File lib/astrails/safe/config/node.rb, line 14 def merge data = {}, &block builder = Builder.new(self, data) builder.instance_eval(&block) if block self end
set(key, value)
click to toggle source
# File lib/astrails/safe/config/node.rb, line 41 def set(key, value) @data[key.to_s] = value end
Also aliased as: []=
set_multi(key, value)
click to toggle source
# File lib/astrails/safe/config/node.rb, line 36 def set_multi(key, value) @data[key.to_s] ||= [] @data[key.to_s].concat [*value] end
to_hash()
click to toggle source
# File lib/astrails/safe/config/node.rb, line 51 def to_hash @data.keys.inject({}) do |res, key| value = @data[key] res[key] = value.is_a?(Node) ? value.to_hash : value res end end