Class: RailsLens::Mailer::Annotator

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_lens/mailer/annotator.rb

Overview

Handles adding mailer annotations to mailer files

Instance Method Summary collapse

Constructor Details

#initialize(dry_run: false) ⇒ Annotator

Returns a new instance of Annotator.



7
8
9
10
11
# File 'lib/rails_lens/mailer/annotator.rb', line 7

def initialize(dry_run: false)
  @dry_run = dry_run
  @mailers = RailsLens::Mailer::Extractor.call
  @changed_files = Set.new
end

Instance Method Details

#annotate_all(pattern: '**/*_mailer.rb', exclusion: 'vendor/**/*_mailer.rb') ⇒ Set<String>

Annotate all mailer files with mailer information

Parameters:

  • pattern (String) (defaults to: '**/*_mailer.rb')

    Glob pattern for mailer files

  • exclusion (String) (defaults to: 'vendor/**/*_mailer.rb')

    Glob pattern for files to exclude

Returns:

  • (Set<String>)

    Set of changed files



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rails_lens/mailer/annotator.rb', line 18

def annotate_all(pattern: '**/*_mailer.rb', exclusion: 'vendor/**/*_mailer.rb')
  # Simply annotate all mailer files we found via their source locations
  source_paths_map.each do |source_path, methods|
    # Skip vendor files or files matching exclusion pattern
    next if exclusion && source_path.include?('vendor/')

    annotate_file(path: source_path, methods: methods) if File.exist?(source_path)
  end

  @changed_files
end

#remove_all(pattern: '**/*_mailer.rb', exclusion: 'vendor/**/*_mailer.rb') ⇒ Set<String>

Remove mailer annotations from all mailer files

Parameters:

  • pattern (String) (defaults to: '**/*_mailer.rb')

    Glob pattern for mailer files

  • exclusion (String) (defaults to: 'vendor/**/*_mailer.rb')

    Glob pattern for files to exclude

Returns:

  • (Set<String>)

    Set of changed files



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rails_lens/mailer/annotator.rb', line 35

def remove_all(pattern: '**/*_mailer.rb', exclusion: 'vendor/**/*_mailer.rb')
  # Remove annotations from all mailer files we found via their source locations
  source_paths_map.each_key do |source_path|
    # Skip vendor files or files matching exclusion pattern
    next if exclusion && source_path.include?('vendor/')

    remove_annotations_from_file(source_path) if File.exist?(source_path)
  end

  @changed_files
end