Sha256: b6ca4efb9705129a2e60683a255ba4c2c1357e6cde3ee190c57da47943126da4

Contents?: true

Size: 1.76 KB

Versions: 15

Compression:

Stored size: 1.76 KB

Contents

# coding: utf-8

require 'set'

module  Fig; end
class   Fig::Command; end
module  Fig::Command::Action; end
module  Fig::Command::Action::Role; end

# Requires a #node_content(package, config_name) method.
module Fig::Command::Action::Role::ListAsGraphviz
  def execute()
    @subgraphs = {}

    puts 'digraph {'
    puts '    node [shape = box];'
    walk_dependency_tree(
      @execution_context.base_package,
      base_display_config_names(),
      include_emit,
      &package_gather
    )
    emit_subgraphs
    puts '}'

    return Fig::Command::Action::EXIT_SUCCESS
  end

  private

  def include_emit
    visited = Set.new

    return lambda do
      |including_package, including_config, included_package, included_config|

      including_name = node_name(including_package, including_config)
      included_name = node_name(included_package, included_config)
      edge = %Q/    "#{including_name}" -> "#{included_name}";/

      if ! visited.include? edge
        visited << edge
        puts edge
      end
    end
  end

  def package_gather
    visited = Set.new

    return lambda do
      |package, config_name, depth|

      name = node_name package, config_name

      if ! visited.include? name
        visited << name

        package_name = node_name package, nil
        @subgraphs[package_name] ||= []
        @subgraphs[package_name] << node_content(package, config_name)
      end
    end
  end

  def emit_subgraphs()
    @subgraphs.each do
      |package_name, nodes|

      cluster = nodes.size > 1 ? 'cluster ' : ''
      puts %Q<    subgraph "#{cluster}#{package_name}" {>
      nodes.each { |node| puts %Q<        #{node}> }
      puts %q<    }>
    end

    return
  end

  def node_name(package, config_name)
    return package.to_s_with_config(config_name)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
fig-1.27.10 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.27.8 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.27.5 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.27.4 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.27.3 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.27.0 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.26.1.beta.1 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.26.0 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.25.1.beta.1 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.25.0 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.24.1.beta.3 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.24.1.beta.2 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.24.1.beta.1 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.24.0 lib/fig/command/action/role/list_as_graphviz.rb
fig-1.23.1.beta.1 lib/fig/command/action/role/list_as_graphviz.rb