class Sus::Tree
def initialize(context)
def initialize(context) @context = context end
def to_json(options = nil)
def to_json(options = nil) traverse do |context| [context.identity.to_s, context.description.to_s, context.leaf?] end.to_json(options) end
def traverse(current = @context, &block)
def traverse(current = @context, &block) node = {} node[:self] = yield(current) if children = current.children # and children.any? node[:children] = children.values.map do |context| self.traverse(context, &block) end end return node end