Sha256: d977be4b909f7f897f144fec4ac7ab8f931d41c6af6c8756da1197c55d41446e

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

# This module provides methods for annotating config/routes.rb.
module AnnotateRb
  module RouteAnnotator
    # This class is abstract class of classes adding and removing annotation to config/routes.rb.
    class RemovalProcessor < BaseProcessor
      # @return [String]
      def execute
        if routes_file_exist?
          if update
            "Annotations were removed from #{routes_file}."
          else
            "#{routes_file} was not changed (Annotation did not exist)."
          end
        else
          "#{routes_file} could not be found."
        end
      end

      private

      def generate_new_content_array(content, header_position)
        if header_position == :before
          content.shift while content.first == ''
        elsif header_position == :after
          content.pop while content.last == ''
        end

        # Make sure we end on a trailing newline.
        content << '' unless content.last == ''

        # TODO: If the user buried it in the middle, we should probably see about
        # TODO: preserving a single line of space between the content above and
        # TODO: below...
        content
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
annotaterb-4.1.1 lib/annotate_rb/route_annotator/removal_processor.rb
annotaterb-4.1.0 lib/annotate_rb/route_annotator/removal_processor.rb
annotaterb-4.0.0 lib/annotate_rb/route_annotator/removal_processor.rb
annotaterb-4.0.0.beta.1 lib/annotate_rb/route_annotator/removal_processor.rb