<commit_before>module VersionLocker
  class Locker
    attr_reader :options
    GEM_PATTERN = /^(?<indentation> *)gem +['"](?<name>.+?)['"](, ['"](?<version>(~> *)?[\d\.]+)['"])?(?<options>, [^$#]+)?.*$/

    def initialize(options = {})
      @options = options
    end

    def spermy?
      options.fetch(:spermy) { true }
    end

    def gemfile_path
      options.fetch(:gemfile_path) { 'Gemfile' }
    end

    def lock!
      new_content = new_gemfile
      with_target do |target|
        target.write new_content
      end
    end

    private

    def with_target
      if options[:target]
        yield options[:target]
      else
        File.open(gemfile_path, 'w'){|f| yield f}
      end
    end

    def old_gemfile_lines
      source_text = options.fetch(:source) { File.read(gemfile_path) }
      source_text.lines
    end

    def new_gemfile
      old_gemfile_lines.map {|line| new_gemfile_line(line) }.join
    end

    def new_gemfile_line(line)
      if match = GEM_PATTERN.match(line) and valid_options?(match[:options]) and version = gem_version(match)
        lock_line(match, version)
      else
        line
      end
    end

    def valid_options?(options)
      options !~ /git|path/
    end

    def gem_version(match)
      return unless spec = Gem.loaded_specs[match[:name]]
      spec.version
    end

    def lock_line(match, version)
      "#{match[:indentation]} gem \"#{match[:name]}\", \"#{'~>' if spermy?}#{version}\"#{match[:options]}\n"
    end
  end
end


<commit_msg>updated pattern<commit_after>module VersionLocker
  class Locker
    attr_reader :options
    GEM_PATTERN = /^(?<indentation> *)gem +['"](?<name>.+?)['"](, ['"](?<version>(~> *)?[\d\.]+)['"])?(?<options>, [^#]+?)?( *#.+)?$/

    def initialize(options = {})
      @options = options
    end

    def spermy?
      options.fetch(:spermy) { true }
    end

    def gemfile_path
      options.fetch(:gemfile_path) { 'Gemfile' }
    end

    def lock!
      new_content = new_gemfile
      with_target do |target|
        target.write new_content
      end
    end

    private

    def with_target
      if options[:target]
        yield options[:target]
      else
        File.open(gemfile_path, 'w'){|f| yield f}
      end
    end

    def old_gemfile_lines
      source_text = options.fetch(:source) { File.read(gemfile_path) }
      source_text.lines
    end

    def new_gemfile
      old_gemfile_lines.map {|line| new_gemfile_line(line) }.join
    end

    def new_gemfile_line(line)
      if match = GEM_PATTERN.match(line) and valid_options?(match[:options]) and version = gem_version(match)
        lock_line(match, version)
      else
        line
      end
    end

    def valid_options?(options)
      options !~ /git|path/
    end

    def gem_version(match)
      return unless spec = Gem.loaded_specs[match[:name]]
      spec.version
    end

    def lock_line(match, version)
      "#{match[:indentation]}gem \"#{match[:name]}\", \"#{'~>' if spermy?}#{version}\"#{match[:options]}\n"
    end
  end
end



{'fraction_non_alphanumeric': 0.14549653579676675, 'fraction_numerical': 0.0, 'mean_word_length': 2.5839243498817965, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7433259', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1024, 'n_words': 212}