Class: AnnotateRb::ModelAnnotator::ProjectAnnotationRemover

Inherits:
Object
  • Object
show all
Defined in:
lib/annotate_rb/model_annotator/project_annotation_remover.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ProjectAnnotationRemover

Returns a new instance of ProjectAnnotationRemover.



6
7
8
# File 'lib/annotate_rb/model_annotator/project_annotation_remover.rb', line 6

def initialize(options)
  @options = options
end

Instance Method Details

#remove_annotationsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/annotate_rb/model_annotator/project_annotation_remover.rb', line 10

def remove_annotations
  project_model_files = model_files

  removal_instructions = project_model_files.map do |path, filename|
    file = File.join(path, filename)

    if AnnotationDecider.new(file, @options).annotate?
      _instructions = build_instructions_for_file(file)
    end
  end.flatten.compact

  deannotated = removal_instructions.map do |instruction|
    if SingleFileAnnotationRemover.call_with_instructions(instruction)
      instruction.file
    end
  rescue => e
    warn "Unable to process #{File.join(instruction.file)}: #{e.message}"
    warn "\t" + e.backtrace.join("\n\t") if @options[:trace]
  end.flatten.compact

  if deannotated.empty?
    puts "Model files unchanged."
  else
    puts "Removed annotations (#{deannotated.length}) from: #{deannotated.join(", ")}"
  end
end