Class: Ace::Git::Organisms::DiffOrchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git/organisms/diff_orchestrator.rb

Overview

Orchestrates the complete diff workflow (NO caching per task decisions) Migrated from ace-git-diff

Class Method Summary collapse

Class Method Details

.for_range(range, options = {}) ⇒ Models::DiffResult

Generate diff for a specific range

Parameters:

  • range (String)

    Git range (e.g., “HEAD~5..HEAD”)

  • options (Hash) (defaults to: {})

    Additional options

Returns:



61
62
63
# File 'lib/ace/git/organisms/diff_orchestrator.rb', line 61

def for_range(range, options = {})
  generate(options.merge(ranges: [range]))
end

.from_config(config_hash) ⇒ Models::DiffResult

Generate diff from configuration hash

Parameters:

  • config_hash (Hash)

    Configuration from YAML or other source

Returns:



52
53
54
55
# File 'lib/ace/git/organisms/diff_orchestrator.rb', line 52

def from_config(config_hash)
  diff_config = Molecules::ConfigLoader.extract_diff_config(config_hash)
  generate(diff_config)
end

.generate(options = {}) ⇒ Models::DiffResult

Generate diff with full workflow: config -> generate -> filter -> result

Parameters:

  • options (Hash) (defaults to: {})

    Options for diff generation

Options Hash (options):

  • :since (String)

    Date or commit to diff from

  • :ranges (Array<String>)

    Git ranges to diff

  • :paths (Array<String>)

    Path patterns to include

  • :exclude_patterns (Array<String>)

    Patterns to exclude

  • :exclude_whitespace (Boolean)

    Exclude whitespace changes

  • :exclude_renames (Boolean)

    Exclude renames

  • :format (Symbol)

    Output format (:diff or :summary)

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ace/git/organisms/diff_orchestrator.rb', line 20

def generate(options = {})
  # Load configuration
  config = Molecules::ConfigLoader.load(options)

  # Short-circuit for grouped_stats — only numstat needed, skip full diff
  if config.format == :grouped_stats
    return build_grouped_stats_result(config, nil, filtered: !config.exclude_patterns.empty?)
  end

  # Generate raw diff
  raw_diff = Molecules::DiffGenerator.generate(config)

  # Filter diff
  filtered_diff = Molecules::DiffFilter.filter(raw_diff, config)

  # Parse and create result
  parsed = Atoms::DiffParser.parse(filtered_diff)

  Models::DiffResult.from_parsed(
    parsed,
    metadata: {
      config: config.to_h,
      generated_at: Time.now.iso8601,
      filtered: !config.exclude_patterns.empty?
    },
    filtered: !config.exclude_patterns.empty?
  )
end

.raw(options = {}) ⇒ Models::DiffResult

Generate raw (unfiltered) diff

Parameters:

  • options (Hash) (defaults to: {})

    Options for diff generation

Returns:



98
99
100
101
102
# File 'lib/ace/git/organisms/diff_orchestrator.rb', line 98

def raw(options = {})
  # Temporarily override exclude patterns to be empty
  options_with_no_filtering = options.merge(exclude_patterns: [])
  generate(options_with_no_filtering)
end

.save_to_file(output_path, options = {}) ⇒ String

Generate diff and save to file

Parameters:

  • output_path (String)

    Path to save the diff

  • options (Hash) (defaults to: {})

    Options for diff generation

Returns:

  • (String)

    Path to the saved file



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/ace/git/organisms/diff_orchestrator.rb', line 108

def save_to_file(output_path, options = {})
  result = generate(options)

  # Create parent directories if needed
  require "fileutils"
  FileUtils.mkdir_p(File.dirname(output_path)) unless File.dirname(output_path) == "."

  # Write content to file
  File.write(output_path, result.content)

  output_path
end

.save_with_format(output_path, format: :diff, **options) ⇒ String

Generate diff and save to file (with explicit format)

Parameters:

  • output_path (String)

    Path to save the diff

  • format (Symbol) (defaults to: :diff)

    Format (:diff or :summary)

  • options (Hash)

    Options for diff generation

Returns:

  • (String)

    Path to the saved file



126
127
128
129
# File 'lib/ace/git/organisms/diff_orchestrator.rb', line 126

def save_with_format(output_path, format: :diff, **options)
  options_with_format = options.merge(format: format)
  save_to_file(output_path, options_with_format)
end

.since(since, options = {}) ⇒ Models::DiffResult

Generate diff since a date or commit

Parameters:

  • since (String)

    Date or commit reference

  • options (Hash) (defaults to: {})

    Additional options

Returns:



69
70
71
# File 'lib/ace/git/organisms/diff_orchestrator.rb', line 69

def since(since, options = {})
  generate(options.merge(since: since))
end

.smart(options = {}) ⇒ Models::DiffResult

Generate diff with smart defaults (based on git state)

Parameters:

  • options (Hash) (defaults to: {})

    Additional options

Returns:



90
91
92
93
# File 'lib/ace/git/organisms/diff_orchestrator.rb', line 90

def smart(options = {})
  # Use empty config to trigger smart default behavior in DiffGenerator
  generate(options)
end

.staged(options = {}) ⇒ Models::DiffResult

Generate staged diff

Parameters:

  • options (Hash) (defaults to: {})

    Additional options

Returns:



76
77
78
# File 'lib/ace/git/organisms/diff_orchestrator.rb', line 76

def staged(options = {})
  generate(options.merge(format: :staged))
end

.working(options = {}) ⇒ Models::DiffResult

Generate working directory diff

Parameters:

  • options (Hash) (defaults to: {})

    Additional options

Returns:



83
84
85
# File 'lib/ace/git/organisms/diff_orchestrator.rb', line 83

def working(options = {})
  generate(options.merge(format: :working))
end