Class: RailsFlowMap::GitDiffFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_flow_map/formatters/git_diff_formatter.rb

Overview

Compares two graph states and visualizes the differences

This formatter analyzes changes between two versions of an application’s architecture, highlighting additions, removals, and modifications. It can output in multiple formats including Mermaid, HTML, and plain text.

Examples:

Basic usage

before = RailsFlowMap.analyze_at('main')
after = RailsFlowMap.analyze
formatter = GitDiffFormatter.new(before, after)
diff = formatter.format

HTML output with custom options

formatter = GitDiffFormatter.new(before, after, {
  format: :html,
  include_metrics: true,
  highlight_breaking_changes: true
})

Instance Method Summary collapse

Constructor Details

#initialize(before_graph, after_graph, options = {}) ⇒ GitDiffFormatter

Creates a new diff formatter

Options Hash (options):

  • :format (Symbol)

    Output format (:mermaid, :html, :text) (default: :mermaid)

  • :include_metrics (Boolean)

    Include complexity metrics (default: true)

  • :highlight_breaking_changes (Boolean)

    Highlight breaking changes (default: true)



32
33
34
35
36
37
# File 'lib/rails_flow_map/formatters/git_diff_formatter.rb', line 32

def initialize(before_graph, after_graph, options = {})
  @before_graph = before_graph
  @after_graph = after_graph
  @options = options
  @format = options[:format] || :mermaid
end

Instance Method Details

#formatString

Generates the diff visualization

Raises:

  • (ArgumentError)

    If an unknown format is specified



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rails_flow_map/formatters/git_diff_formatter.rb', line 43

def format
  diff_result = analyze_differences
  
  case @format
  when :mermaid
    format_as_mermaid(diff_result)
  when :html
    format_as_html(diff_result)
  else
    format_as_text(diff_result)
  end
end