Class: DiverDown::Web::DefinitionToDot::DotMetadataStore

Inherits:
Object
  • Object
show all
Defined in:
lib/diver_down/web/definition_to_dot.rb

Constant Summary collapse

DotMetadata =
Data.define(:id, :type, :data, :metadata) do
  # @return [Hash]
  def to_h
    case type
    when :source
      source_to_h
    when :dependency
      dependency_to_h
    when :module
      module_to_h
    else
      raise NotImplementedError, "not implemented yet #{type}"
    end
  end

  private

  def source_to_h
    {
      id:,
      type: 'source',
      source_name: data.source_name,
      memo: .source(data.source_name).memo,
      module: .source(data.source_name).module,
    }
  end

  def dependency_to_h
    {
      id:,
      type: 'dependency',
      dependencies: data.map do |dependency|
        {
          source_name: dependency.source_name,
          method_ids: dependency.method_ids.sort.map do
            {
              name: _1.name,
              context: _1.context,
            }
          end,
        }
      end,
    }
  end

  def module_to_h
    {
      id:,
      type: 'module',
      module: data,
    }
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(metadata) ⇒ DotMetadataStore

Returns a new instance of DotMetadataStore.



69
70
71
72
73
74
75
# File 'lib/diver_down/web/definition_to_dot.rb', line 69

def initialize()
  @prefix = 'graph_'
  @metadata = 

  # Hash{ id => DotMetadata }
  @to_h = {}
end

Instance Method Details

#append_dependency(id, dependency) ⇒ Object

Parameters:



104
105
106
107
108
109
# File 'lib/diver_down/web/definition_to_dot.rb', line 104

def append_dependency(id, dependency)
   = @to_h.fetch(id)
  dependencies = .data
  combined_dependencies = DiverDown::Definition::Dependency.combine(*dependencies, dependency)
  .data.replace(combined_dependencies)
end

#issue_dependency_id(dependency) ⇒ String

Parameters:

Returns:

  • (String)


86
87
88
# File 'lib/diver_down/web/definition_to_dot.rb', line 86

def issue_dependency_id(dependency)
  (:dependency, [dependency])
end

#issue_module_id(modulee) ⇒ String

Parameters:

  • module_names (Array<String>)

Returns:

  • (String)


92
93
94
95
96
97
98
99
100
# File 'lib/diver_down/web/definition_to_dot.rb', line 92

def issue_module_id(modulee)
   = @to_h.values.find { _1.type == :module && _1.data == modulee }

  if 
    .id
  else
    (:module, modulee)
  end
end

#issue_source_id(source) ⇒ String

Parameters:

Returns:

  • (String)


80
81
82
# File 'lib/diver_down/web/definition_to_dot.rb', line 80

def issue_source_id(source)
  (:source, source)
end

#to_aArray<Hash>

Returns:

  • (Array<Hash>)


112
113
114
# File 'lib/diver_down/web/definition_to_dot.rb', line 112

def to_a
  @to_h.values.map(&:to_h)
end