<commit_before>%w[css js vcs].each do |x|
  require File.join(File.dirname(__FILE__), 'asset_hat', x)
end

module AssetHat
  RAILS_ROOT      = File.join(File.dirname(__FILE__), '..') unless defined?(RAILS_ROOT)
  TYPES           = [:css, :js]
  ASSETS_DIR      = defined?(Rails.public_path) ? Rails.public_path : 'public'
  JAVASCRIPTS_DIR = "#{ASSETS_DIR}/javascripts"
  STYLESHEETS_DIR = "#{ASSETS_DIR}/stylesheets"
  CONFIG_FILEPATH = File.join('config', 'assets.yml')

  def self.config
    @@config ||= YAML::load(File.open(CONFIG_FILEPATH, 'r'))
  end

  def self.assets_dir(type)
    case type.to_sym
    when :css ; STYLESHEETS_DIR
    when :js  ; JAVASCRIPTS_DIR
    end
  end

  def self.asset_exists?(filename, type)
    # Process arguments
    type = type.to_sym
    unless TYPES.include?(type)
      raise "Unknown type \"#{type}\"; should be one of: #{TYPES.join(', ')}."
      return
    end

    @@asset_exists ||= TYPES.inject({}) do |hsh, known_type|
      hsh.merge!(known_type => {})
    end
    if @@asset_exists[type][filename].nil?
      @@asset_exists[type][filename] =
        File.exist?(File.join(self.assets_dir(type), filename))
    end
    @@asset_exists[type][filename]
  end

  def self.cache? ; ActionController::Base.perform_caching ; end

  def self.min_filepath(filepath, extension)
    filepath.sub(/([^\.]*).#{extension}$/, "\\1.min.#{extension}")
  end

  def self.bundle_filenames(bundle, type)
    # Usage:
    #
    #     AssetHat::bundle_filenames('application', :css)
    #       # => ['reset', 'application', 'clearfix']
    #     AssetHat::bundle_filenames('non-existent-file', :css)
    #       # => nil

    # Process arguments
    unless TYPES.include?(type.to_sym)
      raise "Unknown type \"#{type}\"; should be one of: #{TYPES.join(', ')}."
      return
    end

    self.config[type.to_s]['bundles'][bundle]
  end

  def self.bundle_filepaths(bundle, type)
    # Usage:
    #
    #     AssetHat::bundle_filenames('application', :css)
    #       # => ['reset', 'application', 'clearfix']
    #     AssetHat::bundle_filenames('non-existent-file', :css)
    #       # => nil

    # Process arguments
    unless TYPES.include?(type.to_sym)
      raise "Unknown type \"#{type}\"; should be one of: #{TYPES.join(', ')}."
      return
    end

    dir = self.assets_dir(type)
    filenames = self.bundle_filenames(bundle, type)
    filepaths = filenames.map { |fn| File.join(dir, "#{fn}.#{type}") }
  end

end<commit_msg>Added error handling to `AssetHat::bundle_filenames` and `AssetHat::bundle_filepaths`<commit_after>%w[css js vcs].each do |x|
  require File.join(File.dirname(__FILE__), 'asset_hat', x)
end

module AssetHat
  RAILS_ROOT      = File.join(File.dirname(__FILE__), '..') unless defined?(RAILS_ROOT)
  TYPES           = [:css, :js]
  ASSETS_DIR      = defined?(Rails.public_path) ? Rails.public_path : 'public'
  JAVASCRIPTS_DIR = "#{ASSETS_DIR}/javascripts"
  STYLESHEETS_DIR = "#{ASSETS_DIR}/stylesheets"
  CONFIG_FILEPATH = File.join('config', 'assets.yml')

  def self.config
    @@config ||= YAML::load(File.open(CONFIG_FILEPATH, 'r'))
  end

  def self.assets_dir(type)
    case type.to_sym
    when :css ; STYLESHEETS_DIR
    when :js  ; JAVASCRIPTS_DIR
    end
  end

  def self.asset_exists?(filename, type)
    # Process arguments
    type = type.to_sym
    unless TYPES.include?(type)
      raise "Unknown type \"#{type}\"; should be one of: #{TYPES.join(', ')}."
      return
    end

    @@asset_exists ||= TYPES.inject({}) do |hsh, known_type|
      hsh.merge!(known_type => {})
    end
    if @@asset_exists[type][filename].nil?
      @@asset_exists[type][filename] =
        File.exist?(File.join(self.assets_dir(type), filename))
    end
    @@asset_exists[type][filename]
  end

  def self.cache? ; ActionController::Base.perform_caching ; end

  def self.min_filepath(filepath, extension)
    filepath.sub(/([^\.]*).#{extension}$/, "\\1.min.#{extension}")
  end

  def self.bundle_filenames(bundle, type)
    # Usage:
    #
    #     AssetHat::bundle_filenames('application', :css)
    #       # => ['reset', 'application', 'clearfix']
    #     AssetHat::bundle_filenames('non-existent-file', :css)
    #       # => nil

    # Process arguments
    unless TYPES.include?(type.to_sym)
      raise "Unknown type \"#{type}\"; should be one of: #{TYPES.join(', ')}."
      return
    end

    self.config[type.to_s]['bundles'][bundle] rescue nil
  end

  def self.bundle_filepaths(bundle, type)
    # Usage:
    #
    #     AssetHat::bundle_filenames('application', :css)
    #       # => ['reset', 'application', 'clearfix']
    #     AssetHat::bundle_filenames('non-existent-file', :css)
    #       # => nil

    # Process arguments
    unless TYPES.include?(type.to_sym)
      raise "Unknown type \"#{type}\"; should be one of: #{TYPES.join(', ')}."
      return
    end

    dir = self.assets_dir(type)
    filenames = self.bundle_filenames(bundle, type)
    filepaths = filenames.present? ?
      filenames.map { |fn| File.join(dir, "#{fn}.#{type}") } : nil
  end

end
{'fraction_non_alphanumeric': 0.16264345073209338, 'fraction_numerical': 0.0003957261574990107, 'mean_word_length': 3.1639209225700164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2435246', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1804, 'n_words': 331}