Sha256: 414a81667186af3bd2f20f1b6dba8821af956e7c2c559a4033fa1efb59c073c4

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module AnnotateRb
  module ModelAnnotator
    class SingleFileAnnotationRemover
      class << self
        def call_with_instructions(instruction)
          call(instruction.file, instruction.options)
        end

        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
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
annotaterb-4.5.0 lib/annotate_rb/model_annotator/single_file_annotation_remover.rb
annotaterb-4.4.1 lib/annotate_rb/model_annotator/single_file_annotation_remover.rb
annotaterb-4.4.0 lib/annotate_rb/model_annotator/single_file_annotation_remover.rb
annotaterb-4.3.1 lib/annotate_rb/model_annotator/single_file_annotation_remover.rb
annotaterb-4.3.0 lib/annotate_rb/model_annotator/single_file_annotation_remover.rb
annotaterb-4.2.0 lib/annotate_rb/model_annotator/single_file_annotation_remover.rb