Sha256: e9c7fe77dea3de1df321f7db480d2a015f308ba30c557a2a9030e0e00ec98298

Contents?: true

Size: 694 Bytes

Versions: 4

Compression:

Stored size: 694 Bytes

Contents

# frozen_string_literal: true

module AnnotateRb
  module ModelAnnotator
    class FileAnnotationRemover
      class << self
        def call(file_name, options = Options.from({}))
          if File.exist?(file_name)
            content = File.read(file_name)
            return false if content =~ /#{Constants::SKIP_ANNOTATION_PREFIX}.*\n/

            wrapper_open = options[:wrapper_open] ? "# #{options[:wrapper_open]}\n" : ''
            content.sub!(/(#{wrapper_open})?#{AnnotationPatternGenerator.call(options)}/, '')

            File.open(file_name, 'wb') { |f| f.puts content }

            true
          else
            false
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
annotaterb-4.1.1 lib/annotate_rb/model_annotator/file_annotation_remover.rb
annotaterb-4.1.0 lib/annotate_rb/model_annotator/file_annotation_remover.rb
annotaterb-4.0.0 lib/annotate_rb/model_annotator/file_annotation_remover.rb
annotaterb-4.0.0.beta.1 lib/annotate_rb/model_annotator/file_annotation_remover.rb