Class: Renderer::Navigator

Inherits:
Object
  • Object
show all
Defined in:
lib/renderer/navigator.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_name, config) ⇒ Navigator

Returns a new instance of Navigator.



5
6
7
8
9
10
11
# File 'lib/renderer/navigator.rb', line 5

def initialize(file_name, config)
  @nodes = []
  @edges = []
  @file_name = file_name
  @config = config
  @categories = Set.new()
end

Instance Method Details

#add_edge(from, to, opts) ⇒ Object



20
21
22
# File 'lib/renderer/navigator.rb', line 20

def add_edge(from, to, opts)
  @edges << {id: "#{from}-#{to}", from: from, to: to, label: opts[:label]}
end

#add_node(name, opts) ⇒ Object



13
14
15
16
17
18
# File 'lib/renderer/navigator.rb', line 13

def add_node(name, opts)
  vpc = opts[:vpc_id] || 'default'
  info = "<b>Security group</b>: #{name}, <br/><b>VPC:</b> #{vpc}"
  @nodes << {id: name, label: name, categories: [vpc], info: info}
  @categories.add(vpc)
end

#outputObject



24
25
26
27
28
29
30
# File 'lib/renderer/navigator.rb', line 24

def output
  IO.write(@file_name, {
    data: {nodes: @nodes, edges: @edges}, 
    categories: Hash[@categories.map{|c| [c, c]}]
  }.to_json)
  Renderer.copy_asset('navigator.html', @file_name)
end