Class: Ast::Merge::Recipe::Runner
- Inherits:
-
Object
- Object
- Ast::Merge::Recipe::Runner
- Defined in:
- lib/ast/merge/recipe/runner.rb
Overview
Executes a merge recipe against target files.
The runner:
- Loads the template file
- Expands target file globs
- For each target, finds the injection point and performs the merge
- Collects results for reporting
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#base_dir ⇒ String
readonly
Base directory for path resolution.
-
#dry_run ⇒ Boolean
readonly
Whether this is a dry run.
-
#parser ⇒ Symbol
readonly
Parser to use (:markly, :commonmarker, :prism, :psych, etc.).
-
#recipe ⇒ Config
readonly
The recipe being executed.
-
#results ⇒ Array<Result>
readonly
Results from the last run.
-
#target_files ⇒ Array<String>?
readonly
Target files override (from command line).
Instance Method Summary collapse
-
#initialize(recipe, dry_run: false, base_dir: nil, parser: :markly, verbose: false, target_files: nil, **options) ⇒ Runner
constructor
Initialize a recipe runner.
-
#results_by_status ⇒ Hash<Symbol, Array<Result>>
Get results grouped by status.
-
#results_table ⇒ Array<Hash>
Format results as an array of hashes for TableTennis.
-
#run ⇒ Array<Result>
Run the recipe against all target files.
-
#summary ⇒ Hash
Get a summary hash of the run.
-
#summary_table ⇒ Array<Hash>
Format summary as an array of hashes for TableTennis.
Constructor Details
#initialize(recipe, dry_run: false, base_dir: nil, parser: :markly, verbose: false, target_files: nil, **options) ⇒ Runner
Initialize a recipe runner.
57 58 59 60 61 62 63 64 65 |
# File 'lib/ast/merge/recipe/runner.rb', line 57 def initialize(recipe, dry_run: false, base_dir: nil, parser: :markly, verbose: false, target_files: nil, **) @recipe = recipe @dry_run = dry_run @base_dir = base_dir || Dir.pwd @parser = parser @verbose = verbose @target_files = target_files @results = [] end |
Instance Attribute Details
#base_dir ⇒ String (readonly)
Returns Base directory for path resolution.
38 39 40 |
# File 'lib/ast/merge/recipe/runner.rb', line 38 def base_dir @base_dir end |
#dry_run ⇒ Boolean (readonly)
Returns Whether this is a dry run.
35 36 37 |
# File 'lib/ast/merge/recipe/runner.rb', line 35 def dry_run @dry_run end |
#parser ⇒ Symbol (readonly)
Returns Parser to use (:markly, :commonmarker, :prism, :psych, etc.).
41 42 43 |
# File 'lib/ast/merge/recipe/runner.rb', line 41 def parser @parser end |
#recipe ⇒ Config (readonly)
Returns The recipe being executed.
32 33 34 |
# File 'lib/ast/merge/recipe/runner.rb', line 32 def recipe @recipe end |
#results ⇒ Array<Result> (readonly)
Returns Results from the last run.
47 48 49 |
# File 'lib/ast/merge/recipe/runner.rb', line 47 def results @results end |
#target_files ⇒ Array<String>? (readonly)
Returns Target files override (from command line).
44 45 46 |
# File 'lib/ast/merge/recipe/runner.rb', line 44 def target_files @target_files end |
Instance Method Details
#results_by_status ⇒ Hash<Symbol, Array<Result>>
Get results grouped by status.
96 97 98 |
# File 'lib/ast/merge/recipe/runner.rb', line 96 def results_by_status @results.group_by(&:status) end |
#results_table ⇒ Array<Hash>
Format results as an array of hashes for TableTennis.
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ast/merge/recipe/runner.rb', line 118 def results_table @results.map do |r| { file: r.relative_path, status: r.status.to_s, changed: r.changed ? "yes" : "no", message: r., } end end |
#run ⇒ Array<Result>
Run the recipe against all target files.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ast/merge/recipe/runner.rb', line 70 def run @results = [] template_content = load_template # Use command-line targets if provided, otherwise expand from recipe files_to_process = if @target_files && !@target_files.empty? # Expand paths relative to base_dir @target_files.map { |f| File.(f, @base_dir) } else # Let the recipe expand targets from its own location recipe. end files_to_process.each do |target_path| result = process_file(target_path, template_content) @results << result yield result if block_given? end @results end |
#summary ⇒ Hash
Get a summary hash of the run.
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ast/merge/recipe/runner.rb', line 103 def summary by_status = results_by_status { total: @results.size, updated: (by_status[:updated] || []).size, would_update: (by_status[:would_update] || []).size, unchanged: (by_status[:unchanged] || []).size, skipped: (by_status[:skipped] || []).size, errors: (by_status[:error] || []).size, } end |
#summary_table ⇒ Array<Hash>
Format summary as an array of hashes for TableTennis.
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ast/merge/recipe/runner.rb', line 132 def summary_table s = summary [ {metric: "Total files", value: s[:total]}, {metric: "Updated", value: dry_run ? s[:would_update] : s[:updated]}, {metric: "Unchanged", value: s[:unchanged]}, {metric: "Skipped (no anchor)", value: s[:skipped]}, {metric: "Errors", value: s[:errors]}, ] end |