Class: AnnotateRb::ModelAnnotator::SingleFileAnnotationRemover

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

Class Method Summary collapse

Class Method Details

.call(file_name, options = Options.from({})) ⇒ Object



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

def call(file_name, options = Options.from({}))
  return false unless File.exist?(file_name)
  old_content = File.read(file_name)

  file_components = FileComponents.new(old_content, "", options)

  return false if file_components.has_skip_string?
  # TODO: Uncomment below after tests are fixed
  # return false if !file_components.has_annotations?

  wrapper_open = if options[:wrapper_open]
    "# #{options[:wrapper_open]}\n"
  else
    ""
  end

  generated_pattern = AnnotationPatternGenerator.call(options)
  updated_file_content = old_content.sub!(/(#{wrapper_open})?#{generated_pattern}/, "")

  File.open(file_name, "wb") { |f| f.puts updated_file_content }

  true
end

.call_with_instructions(instruction) ⇒ Object



7
8
9
# File 'lib/annotate_rb/model_annotator/single_file_annotation_remover.rb', line 7

def call_with_instructions(instruction)
  call(instruction.file, instruction.options)
end