<commit_before>require 'erb'
require 'yaml'
require 'pathname'
require 'active_support/core_ext/hash/keys.rb'
require 'active_support/core_ext/string/inflections.rb'

module Setty
  MissingEnviromentError = Class.new(RuntimeError)

  class Loader
    def initialize(path, enviroment)
      @base_path  = Pathname(path)
      @enviroment = enviroment
    end

    def options
      load_options @base_path
    end

    private

    def load_options(path)
      options = load_options_from_file path.sub_ext('.yml')
      find_nested_options(path).each do |sub_path|
        options[sub_path.basename.to_s.to_sym] = load_options sub_path
      end
      options
    end

    def find_nested_options(path)
      Pathname.glob(path.join('*')).map { |file_path| path.join file_path.basename('.yml') }.uniq
    end

    def load_options_from_file(path)
      enviroment_options = load_enviroment_options_from_file path

      raise MissingEnviromentError, %Q(Missing "#{@enviroment}" key in #{path}) if enviroment_options.nil?

      Options[enviroment_options.symbolize_keys]
    end

    def load_enviroment_options_from_file(file)
      return {} unless file.readable?

      yaml_content = ERB.new(file.read).result
      options      = YAML.load yaml_content

      options[@enviroment.to_s]
    end
  end
end
<commit_msg>Always convert envoroment to string<commit_after>require 'erb'
require 'yaml'
require 'pathname'
require 'active_support/core_ext/hash/keys.rb'
require 'active_support/core_ext/string/inflections.rb'

module Setty
  MissingEnviromentError = Class.new(RuntimeError)

  class Loader
    def initialize(path, enviroment)
      @base_path  = Pathname(path)
      @enviroment = enviroment.to_s
    end

    def options
      load_options @base_path
    end

    private

    def load_options(path)
      options = load_options_from_file path.sub_ext('.yml')
      find_nested_options(path).each do |sub_path|
        options[sub_path.basename.to_s.to_sym] = load_options sub_path
      end
      options
    end

    def find_nested_options(path)
      Pathname.glob(path.join('*')).map { |file_path| path.join file_path.basename('.yml') }.uniq
    end

    def load_options_from_file(path)
      enviroment_options = load_enviroment_options_from_file path

      raise MissingEnviromentError, %Q(Missing "#{@enviroment}" key in #{path}) if enviroment_options.nil?

      Options[enviroment_options.symbolize_keys]
    end

    def load_enviroment_options_from_file(file)
      return {} unless file.readable?

      yaml_content = ERB.new(file.read).result
      options      = YAML.load yaml_content

      options[@enviroment]
    end
  end
end

{'fraction_non_alphanumeric': 0.08858858858858859, 'fraction_numerical': 0.0, 'mean_word_length': 3.4639865996649917, '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': '1505416', 'n_tokens_mistral': 906, 'n_tokens_neox': 893, 'n_words': 168}