Sha256: 78b0cef9a2edc86263e083fcabde29c0d28f0967c75ede496549752584fa8aa3

Contents?: true

Size: 834 Bytes

Versions: 11

Compression:

Stored size: 834 Bytes

Contents

class Graph
  attr_reader :ops

  def initialize(config)
    @config = config
    @ops = []
    @nodes = Set.new
  end

  def add_node(name)
    log("node: #{name}")
    uniquely_add(@ops, :node, name) {
      [:node, name]
    }
  end

  def add_edge(from, to, opts)
    log("edge: #{from} -> #{to}")
    add_node(from)
    add_node(to)
    uniquely_add(@ops, :edge, from, to) {
      [:edge, from, to, opts]
    }
  end

  def output(renderer)
    @ops.each { |op, *args|
      renderer.add_node(*args) if op==:node
      renderer.add_edge(*args) if op==:edge
    }
    renderer.output
  end

  def uniquely_add(target, type, *opts, &block)
    return if opts.compact.empty?
    return if @nodes.include?([type, opts])
    @nodes.add([type, opts])
    target << yield
  end


  def log(msg)
    puts msg if @config.debug?
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
aws_security_viz-0.1.4.pre.alpha.pre.81 lib/graph.rb
aws_security_viz-0.1.4.pre.alpha.pre.77 lib/graph.rb
aws_security_viz-0.1.4.pre.alpha.pre.75 lib/graph.rb
aws_security_viz-0.1.4.pre.alpha.pre.73 lib/graph.rb
aws_security_viz-0.1.3 lib/graph.rb
aws_security_viz-0.1.3.pre.alpha.pre.71 lib/graph.rb
aws_security_viz-0.1.3.pre.alpha.pre.70 lib/graph.rb
aws_security_viz-0.1.3.pre.alpha.pre.69 lib/graph.rb
aws_security_viz-0.1.3.pre.alpha.pre.68 lib/graph.rb
aws_security_viz-0.1.3.pre.alpha.pre.64 lib/graph.rb
aws_security_viz-0.1.3.pre.alpha.pre.63 lib/graph.rb