Sha256: 98423780e5eb3cf0c27b28dae73bc8ca9f02e3d56ebea33c8d1733b530a1d1cb

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

module PowerStencil
  module Utils

    module Graphviz

      include UniverseCompiler::Utils::Graphviz

      def graph_entities(entities, filename = nil)
        entities_to_process = unless config[:graphviz][:show_config]
                                entities.reject {|e| e.type == :project_config}
                              else
                                entities
                              end
        graph_entities_to_file entities_to_process,
                               output_file_name: filename,
                               file_type: config[:graphviz][:file_type] do |graph, cache|
          graph[:label] = config[:graphviz][:label]
          graph[:labelloc] = config[:graphviz][:labelloc]
          graph.each_node do |node_name|
            node = graph.get_node node_name
            entity = cache[:by_node][node]

            # Set default node attributes
            config[:graphviz][:node].each do |k,v|
              node[k] = v
            end
            fields_to_display = {}

            # Define node tooltip
            entity.fields.keys.each do |field_name|
              constraints = entity.class.fields_constraints[field_name]
              unless constraints.nil?
                # Remove relations as they are represented as edges
                next if constraints.keys.include? :has_one
                next if constraints.keys.include? :has_many
              end
              fields_to_display[field_name] = entity[field_name]
            end
            node[:tooltip] = fields_to_display.to_yaml

            # specific customizations
            if config[:graphviz][:customizations][entity.type]
              config[:graphviz][:customizations][entity.type].each do |k,v|
                node[k] = v
              end
            end
          end
        end

      end


    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
power_stencil-0.4.2 lib/power_stencil/utils/graphviz.rb
power_stencil-0.4.1 lib/power_stencil/utils/graphviz.rb
power_stencil-0.4.0 lib/power_stencil/utils/graphviz.rb