Sha256: 82ce44e8512732543b85e45349e199894879435393290e4f71b9ef7f5b353893

Contents?: true

Size: 740 Bytes

Versions: 3

Compression:

Stored size: 740 Bytes

Contents

# frozen_string_literal: true

require "graphviz"

module CobraCommander
  module Output
    # Generates graphs of components
    module GraphViz
      def self.generate(component, output)
        g = ::GraphViz.new(:G, type: :digraph, concentrate: true)
        ([component] + component.deep_dependencies).each do |comp|
          g.add_nodes comp.name
          g.add_edges comp.name, comp.dependencies.map(&:name)
        end

        g.output(extract_format(output) => output)
      end

      private_class_method def self.extract_format(output)
        format = output[-3..-1]
        return format if format == "png" || format == "dot"

        raise ArgumentError, "output format must be 'png' or 'dot'"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cobra_commander-0.9.0 lib/cobra_commander/output/graph_viz.rb
cobra_commander-0.8.1 lib/cobra_commander/output/graph_viz.rb
cobra_commander-0.8.0 lib/cobra_commander/output/graph_viz.rb