Sha256: 3c4dc05dccd2593733c44258d92842e715f96b2016cdf5ddfd893e86e48fa7ac

Contents?: true

Size: 688 Bytes

Versions: 2

Compression:

Stored size: 688 Bytes

Contents

# frozen_string_literal: true

require_relative "file_filter"

module KeepUp
  # Filter to update dependency information in a Gemfile.
  class GemfileFilter < FileFilter
    def self.apply(contents, dependency)
      matcher = dependency_matcher(dependency)
      contents.each_line.map do |line|
        if line =~ matcher
          match = Regexp.last_match
          "#{match[1]}#{dependency.version}#{match[2]}"
        else
          line
        end
      end.join
    end

    def self.dependency_matcher(dependency)
      /
        ^(\s*gem\s+['"]#{dependency.name}['"],
        \s+\[?['"](?:~>|=)?\ *)
        [^'"]*
        (['"]\]?[^\]]*)
        $
      /mx
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
keep_up-0.11.0 lib/keep_up/gemfile_filter.rb
keep_up-0.10.2 lib/keep_up/gemfile_filter.rb