Class: RailsLens::Route::Annotator
- Inherits:
-
Object
- Object
- RailsLens::Route::Annotator
- Defined in:
- lib/rails_lens/route/annotator.rb
Overview
Handles adding route annotations to controller files
Instance Method Summary collapse
-
#annotate_all(pattern: '**/*_controller.rb', exclusion: 'vendor/**/*_controller.rb') ⇒ Array<String>
Annotate all controller files with route information.
-
#initialize(dry_run: false) ⇒ Annotator
constructor
A new instance of Annotator.
-
#remove_all(pattern: '**/*_controller.rb', exclusion: 'vendor/**/*_controller.rb') ⇒ Array<String>
Remove route annotations from all controller files.
Constructor Details
Instance Method Details
#annotate_all(pattern: '**/*_controller.rb', exclusion: 'vendor/**/*_controller.rb') ⇒ Array<String>
Annotate all controller files with route information
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rails_lens/route/annotator.rb', line 18 def annotate_all(pattern: '**/*_controller.rb', exclusion: 'vendor/**/*_controller.rb') controller_paths = Rails.root.glob(pattern) .reject { |path| Rails.root.glob(exclusion).include?(path) } source_paths_map.each do |source_path, actions| # Use exact path matching or find controller files by parsing if controller_paths.include?(source_path) || controller_file_exists?(source_path) annotate_file(path: source_path, actions: actions) end end @changed_files end |
#remove_all(pattern: '**/*_controller.rb', exclusion: 'vendor/**/*_controller.rb') ⇒ Array<String>
Remove route annotations from all controller files
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rails_lens/route/annotator.rb', line 37 def remove_all(pattern: '**/*_controller.rb', exclusion: 'vendor/**/*_controller.rb') controller_paths = Rails.root.glob(pattern) .reject { |path| Rails.root.glob(exclusion).include?(path) } # Also include controller files from source paths all_controller_paths = (controller_paths + source_paths_map.keys).uniq all_controller_paths.select! { |path| controller_file_exists?(path) } all_controller_paths.each do |path| remove_annotations_from_file(path) end @changed_files end |