Class: Ace::Idea::Molecules::IdeaDoctorFixer

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/idea/molecules/idea_doctor_fixer.rb

Overview

Handles auto-fixing of common idea issues detected by doctor. Supports dry_run mode to preview fixes without applying them.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dry_run: false, root_dir: nil) ⇒ IdeaDoctorFixer

Returns a new instance of IdeaDoctorFixer.



18
19
20
21
22
23
24
# File 'lib/ace/idea/molecules/idea_doctor_fixer.rb', line 18

def initialize(dry_run: false, root_dir: nil)
  @dry_run = dry_run
  @root_dir = root_dir
  @fixed_count = 0
  @skipped_count = 0
  @fixes_applied = []
end

Instance Attribute Details

#dry_runObject (readonly)

Returns the value of attribute dry_run.



16
17
18
# File 'lib/ace/idea/molecules/idea_doctor_fixer.rb', line 16

def dry_run
  @dry_run
end

#fixed_countObject (readonly)

Returns the value of attribute fixed_count.



16
17
18
# File 'lib/ace/idea/molecules/idea_doctor_fixer.rb', line 16

def fixed_count
  @fixed_count
end

#skipped_countObject (readonly)

Returns the value of attribute skipped_count.



16
17
18
# File 'lib/ace/idea/molecules/idea_doctor_fixer.rb', line 16

def skipped_count
  @skipped_count
end

Instance Method Details

#can_fix?(issue) ⇒ Boolean

Check if an issue can be auto-fixed

Parameters:

  • issue (Hash)

    Issue to check

Returns:

  • (Boolean)


90
91
92
93
94
# File 'lib/ace/idea/molecules/idea_doctor_fixer.rb', line 90

def can_fix?(issue)
  return false unless issue[:location]

  FIXABLE_PATTERNS.any? { |pattern| issue[:message].match?(pattern) }
end

#fix_issue(issue) ⇒ Boolean

Fix a single issue by pattern matching its message

Parameters:

  • issue (Hash)

    Issue to fix

Returns:

  • (Boolean)

    Whether fix was successful



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ace/idea/molecules/idea_doctor_fixer.rb', line 47

def fix_issue(issue)
  case issue[:message]
  when /Missing opening '---' delimiter/
    fix_missing_opening_delimiter(issue[:location])
  when /Missing closing '---' delimiter/
    fix_missing_closing_delimiter(issue[:location])
  when /Missing required field: id/
    fix_missing_id(issue[:location])
  when /Missing required field: status/,
       /Missing recommended field: status/
    fix_missing_status(issue[:location])
  when /Missing required field: title/,
       /Missing recommended field: title/
    fix_missing_title(issue[:location])
  when /Derived field 'location' should not be stored in frontmatter/
    fix_remove_location(issue[:location])
  when /Field 'tags' is not an array/
    fix_tags_not_array(issue[:location])
  when /Missing recommended field: tags/
    fix_missing_tags(issue[:location])
  when /Missing recommended field: created_at/
    fix_missing_created_at(issue[:location])
  when /terminal status.*not in _archive/
    fix_move_to_archive(issue[:location])
  when /in _archive\/ but status is/
    fix_archive_status(issue[:location])
  when /in _maybe\/ with terminal status/
    fix_maybe_terminal(issue[:location])
  when /Stale backup file/
    fix_stale_backup(issue[:location])
  when /Empty directory/
    fix_empty_directory(issue[:location])
  when /Folder name does not match '\{id\}-\{slug\}' convention/
    fix_folder_naming(issue[:location])
  else
    @skipped_count += 1
    false
  end
end

#fix_issues(issues) ⇒ Hash

Fix a batch of issues

Parameters:

  • issues (Array<Hash>)

    Issues to fix

Returns:

  • (Hash)

    Fix results summary



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ace/idea/molecules/idea_doctor_fixer.rb', line 29

def fix_issues(issues)
  fixable_issues = issues.select { |issue| can_fix?(issue) }

  fixable_issues.each do |issue|
    fix_issue(issue)
  end

  {
    fixed: @fixed_count,
    skipped: @skipped_count,
    fixes_applied: @fixes_applied,
    dry_run: @dry_run
  }
end