<commit_before>require 'yaml'
require 'hashie'
# require 'active_support/core_ext/hash'
module AppConfig
  VERSION = "1.1"
  
  def self.clear!
    @configurations = {}
  end
  
  def self.[](key=nil)
    @configurations if key.nil?
    ((@configurations||={})[key.to_s] ||= Accessor.new(key.to_s)).raw
  end
  
  class Accessor
    def initialize(filename)
      @config = load(filename)
    end

    def raw
      @config
    end

    private
    def load(filename)
      conf_yml = ConfHash[
        YAML::load(
          ERB.new(
            IO.read(File.join(Rails.root, 'config', "#{filename}.yml"))).result)]
      
      if defined?(Rails)
        conf_yml[Rails.env]
      else
        conf_yml
      end
    end
  end
  
  class ConfHash < Hash
    alias_method :orig_accessor, :[]
    
    def [] key=nil
      orig_accessor key.to_s
    rescue
      super
    end
  end
end<commit_msg>fixed deep confhash<commit_after>require 'yaml'
require 'hashie'
# require 'active_support/core_ext/hash'
module AppConfig
  VERSION = "1.1.1"
  
  def self.clear!
    @configurations = {}
  end
  
  def self.[](key=nil)
    @configurations if key.nil?
    ((@configurations||={})[key.to_s] ||= Accessor.new(key.to_s)).raw
  end
  
  class Accessor
    def initialize(filename)
      @config = load(filename)
    end

    def raw
      @config
    end

    private
    def load(filename)
      conf_yml = ConfHash[
        YAML::load(
          ERB.new(
            IO.read(File.join(Rails.root, 'config', "#{filename}.yml"))).result)]
      
      if defined?(Rails)
        conf_yml[Rails.env]
      else
        conf_yml
      end
    end
  end
  
  class ConfHash < Hash
    alias_method :orig_accessor, :[]
    
    def new data
      super
      convert_children
    end
    
    def convert_children
      keys.each do |key|
        value = self[key]
        if value.is_a?(Hash)
          value = ConfHash[value]
          value.convert_children
        end
      end
      self
    end
    
    def [] key=nil
      orig_accessor key.to_s
    rescue
      super
    end
  end
end
{'fraction_non_alphanumeric': 0.1079136690647482, 'fraction_numerical': 0.002398081534772182, 'mean_word_length': 1.9672830725462305, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3051457', 'n_tokens_mistral': 726, 'n_tokens_neox': 712, 'n_words': 153}