Class: Aptible::CLI::Renderer::Json

Inherits:
Base
  • Object
show all
Defined in:
lib/aptible/cli/renderer/json.rb

Instance Method Summary collapse

Instance Method Details

#render(node) ⇒ Object



20
21
22
# File 'lib/aptible/cli/renderer/json.rb', line 20

def render(node)
  JSON.pretty_generate(visit(node))
end

#visit(node) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/aptible/cli/renderer/json.rb', line 5

def visit(node)
  case node
  when Formatter::Root
    visit(node.root)
  when Formatter::Object
    Hash[node.children.each_pair.map { |k, c| [k, visit(c)] }]
  when Formatter::List
    node.children.map { |c| visit(c) }
  when Formatter::Value
    node.value
  else
    raise "Unhandled node: #{node.inspect}"
  end
end