lib/arborist/node.rb in arborist-0.1.0 vs lib/arborist/node.rb in arborist-0.2.0.pre20170519125456
- old
+ new
@@ -178,12 +178,11 @@
### Record a new loaded instance if the Thread-local variable is set up to track
### them.
def self::add_loaded_instance( new_instance )
instances = Thread.current[ LOADED_INSTANCE_KEY ] or return
- self.log.debug "Adding new instance %p to loaded instances %p" %
- [ new_instance, instances ]
+ self.log.debug "Adding new instance %p to node tree" % [ new_instance ]
instances << new_instance
end
### Inheritance hook -- add a DSL declarative function for the given +subclass+.
@@ -919,12 +918,12 @@
end
end
### Return a Hash of the node's state.
- def to_h
- return {
+ def to_h( deep: false )
+ hash = {
identifier: self.identifier,
type: self.class.name.to_s.sub( /.+::/, '' ).downcase,
parent: self.parent,
description: self.description,
tags: self.tags,
@@ -936,9 +935,17 @@
status_changed: self.status_changed ? self.status_changed.iso8601 : nil,
errors: self.errors,
dependencies: self.dependencies.to_h,
quieted_reasons: self.quieted_reasons,
}
+
+ if deep
+ hash[ :children ] = self.children.each_with_object( {} ) do |(ident, node), h|
+ h[ ident ] = node.to_h( deep )
+ end
+ end
+
+ return hash
end
### Marshal API -- return the node as an object suitable for marshalling.
def marshal_dump