Sha256: 07a1a994ed0078188eae379695fd0a682feb4dd325182f93dfb03136ed93cf66

Contents?: true

Size: 964 Bytes

Versions: 3

Compression:

Stored size: 964 Bytes

Contents

module LockfilePreserver
  class BundledWith
    def initialize(original, updated)
      @original = original
      @updated = updated
    end

    def keep
      if original.include? BUNDLED_WITH
        keep_bundled_with
      else
        remove_bundled_with
      end
    end

    private

      attr_reader :original, :updated

      BUNDLED_WITH = "BUNDLED WITH".freeze
      REGEXP = %r{\n\nBUNDLED WITH\n\s+(?<version>#{Gem::Version::VERSION_PATTERN})\n*}
      NEW_LINE = "\n".freeze

      private_constant :BUNDLED_WITH
      private_constant :REGEXP
      private_constant :NEW_LINE

      def keep_bundled_with
        updated.sub(REGEXP, bundled_with)
      end

      def remove_bundled_with
        updated.sub(REGEXP, NEW_LINE)
      end

      def bundled_with
        "\n\nBUNDLED WITH\n" \
        "   #{bundler_version}\n"
      end

      def bundler_version
        @_bundler_version ||= original.match(REGEXP)[:version]
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lockfile_preserver-1.0.3 lib/lockfile_preserver/bundled_with.rb
lockfile_preserver-1.0.2 lib/lockfile_preserver/bundled_with.rb
lockfile_preserver-1.0.1 lib/lockfile_preserver/bundled_with.rb