<commit_before>require "rubygems"
require "xmlsimple"
require "open-uri"
require "zlib"

require "bundler"
require "gems-status/gem_simple"
require "gems-status/utils"

module GemsStatus

  class LockfileGems
    attr_reader :filename
    def initialize(conf)
      Utils::check_parameters('LockfileGems', conf, ["filename", "gems_url"])
      @filename = conf['filename']
      @gems_url = conf['gems_url']
    end

    def get_data(dirname, filename)
      data = ""
      Dir.chdir(dirname) do
        begin
          data = File.open(filename).read
        rescue
          Utils::log_error("?", "There was a problem opening file #{filename} ")
        end
      end
      return data
    end

    def gem_list
      gems = {}
      Utils::log_debug "reading #{@filename}"
      Dir.chdir(File.dirname(@filename)) do
        file_data = get_data(File::dirname(@filename), File::basename(@filename))
        if file_data.empty?
          Utils::log_error("?", "file empty #{@filename}")
          return
        end
        lockfile = Bundler::LockfileParser.new(file_data)
        lockfile.specs.each do |spec|
          version = Gem::Version.create(spec.version)
          Utils::log_debug "dependencies for #{spec.name} #{spec.dependencies}"
          gems[spec.name] = GemSimple.new(spec.name, version , nil, 
                                             @filename, gems_url(spec), 
                                             spec.dependencies)
        end
      end
      gems
    end

    private

    def gems_url(spec)
      if spec.source.class.name == "Bundler::Source::Git"
        Utils::log_debug "this comes from git #{spec.name} #{spec.version}"
        spec.source.uri
      else
        @gems_url
      end
    end
  end
end
<commit_msg>replase File.open.read by File.read because this was causing a bug<commit_after>require "rubygems"
require "xmlsimple"
require "open-uri"
require "zlib"

require "bundler"
require "gems-status/gem_simple"
require "gems-status/utils"

module GemsStatus

  class LockfileGems
    attr_reader :filename
    def initialize(conf)
      Utils::check_parameters('LockfileGems', conf, ["filename", "gems_url"])
      @filename = conf['filename']
      @gems_url = conf['gems_url']
    end

    def get_data(dirname, filename)
      data = ""
      Dir.chdir(dirname) do
        begin
          data = File.read(filename)
        rescue
          Utils::log_error("?", "There was a problem opening file #{filename} ")
        end
      end
      return data
    end

    def gem_list
      gems = {}
      Utils::log_debug "reading #{@filename}"
      Dir.chdir(File.dirname(@filename)) do
        file_data = get_data(File::dirname(@filename), File::basename(@filename))
        if file_data.empty?
          Utils::log_error("?", "file empty #{@filename}")
          return
        end
        lockfile = Bundler::LockfileParser.new(file_data)
        lockfile.specs.each do |spec|
          version = Gem::Version.create(spec.version)
          Utils::log_debug "dependencies for #{spec.name} #{spec.dependencies}"
          gems[spec.name] = GemSimple.new(spec.name, version , nil, 
                                             @filename, gems_url(spec), 
                                             spec.dependencies)
        end
      end
      gems
    end

    private

    def gems_url(spec)
      if spec.source.class.name == "Bundler::Source::Git"
        Utils::log_debug "this comes from git #{spec.name} #{spec.version}"
        spec.source.uri
      else
        @gems_url
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1132286995515695, 'fraction_numerical': 0.0, 'mean_word_length': 2.1640070921985815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6425983', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1018, 'n_words': 241}