<commit_before>class Path
  LOADERS = {}

  # Registers a new loader (a block which will be called with the Path to load)
  # for the given extensions (either with the leading dot or not)
  #
  #     Path.register_loader('.marshal') { |file| Marshal.load file.read }
  def self.register_loader(*extensions, &loader)
    extensions.each { |ext|
      ext = ext[1..-1] if ext.start_with? '.'
      LOADERS[ext] = loader
    }
  end

  register_loader 'yml', 'yaml' do |path|
    require 'yaml'
    YAML.load_file(path)
  end

  register_loader 'json' do |path|
    require 'json'
    JSON.load(path.read)
  end

  # Path#load helps loading data from various files.
  # JSON and YAML loaders are provided by default.
  # See Path.register_loader.
  def load
    if LOADERS.key? ext
      LOADERS[ext].call(self)
    else
      raise "Unable to load #{self} (unrecognized extension)"
    end
  end
end<commit_msg>load .gemspec files with eval<commit_after>class Path
  LOADERS = {}

  # Registers a new loader (a block which will be called with the Path to load)
  # for the given extensions (either with the leading dot or not)
  #
  #     Path.register_loader('.marshal') { |file| Marshal.load file.read }
  def self.register_loader(*extensions, &loader)
    extensions.each { |ext|
      ext = ext[1..-1] if ext.start_with? '.'
      LOADERS[ext] = loader
    }
  end

  register_loader 'yml', 'yaml' do |path|
    require 'yaml'
    YAML.load_file(path)
  end

  register_loader 'json' do |path|
    require 'json'
    JSON.load(path.read)
  end

  register_loader 'gemspec' do |path|
    eval path.read
  end

  # Path#load helps loading data from various files.
  # JSON and YAML loaders are provided by default.
  # See Path.register_loader.
  def load
    if LOADERS.key? ext
      LOADERS[ext].call(self)
    else
      raise "Unable to load #{self} (unrecognized extension)"
    end
  end
end
{'fraction_non_alphanumeric': 0.10326659641728135, 'fraction_numerical': 0.002107481559536354, 'mean_word_length': 2.915463917525773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6913704', 'n_tokens_mistral': 638, 'n_tokens_neox': 610, 'n_words': 202}