<commit_before>require "yaml"
require "erb"

# A simple settings solution using a YAML file. See README for more information.
class Settingslogic < Hash
  class << self
    def name # :nodoc:
      instance.key?("name") ? instance.name : super
    end
    
    def source(value = nil)
      if value.nil?
        @source
      else
        @source = value
      end
    end
    
    def namespace(value = nil)
      if value.nil?
        @namespace
      else
        @namespace = value
      end
    end
    
    private
      def instance
        @instance ||= new
      end
      
      def method_missing(name, *args, &block)
        instance.send(name, *args, &block)
      end
  end
  
  # Initializes a new settings object. You can initialize an object in any of the following ways:
  #
  #   Settings.new(:application) # will look for config/application.yml
  #   Settings.new("application.yaml") # will look for application.yaml
  #   Settings.new("/var/configs/application.yml") # will look for /var/configs/application.yml
  #   Settings.new(:config1 => 1, :config2 => 2)
  #
  # Basically if you pass a symbol it will look for that file in the configs directory of your rails app, if you are using this in rails. If you pass a string it should be an absolute path to your settings file.
  # Then you can pass a hash, and it just allows you to access the hash via methods.
  def initialize(hash_or_file = self.class.source)
    case hash_or_file
    when Hash
      self.update hash_or_file
    else
      hash = YAML.load(ERB.new(File.read(hash_or_file)).result).to_hash
      hash = hash[self.class.namespace] if self.class.namespace
      self.update hash
    end
  end
  
  module NodeDefinder

    def singleton(obj)
      class << obj; self; end
    end

    private

    def method_missing(name, *args, &block)
      if key?(name.to_s)
        define_method_for_node_or_leaf name
      else
        super
      end
    end

    def define_method_for_node_or_leaf(name)
      if self[name.to_s].is_a? Hash
        node = self[name.to_s]
        node.extend NodeDefinder
        singleton(self).send(:define_method, name) { node }
        node
      else
        leaf = self[name.to_s]
        singleton(self).send(:define_method, name) { leaf }
        leaf
      end
    end
  end

  include NodeDefinder
end
<commit_msg>NodeDefinder was renamed EigenMethodDefiner. Method 'define_method_for_node_or_leaf' was removed.<commit_after>require "yaml"
require "erb"

# A simple settings solution using a YAML file. See README for more information.
class Settingslogic < Hash
  class << self
    def name # :nodoc:
      instance.key?("name") ? instance.name : super
    end
    
    def source(value = nil)
      if value.nil?
        @source
      else
        @source = value
      end
    end
    
    def namespace(value = nil)
      if value.nil?
        @namespace
      else
        @namespace = value
      end
    end
    
    private
      def instance
        @instance ||= new
      end
      
      def method_missing(name, *args, &block)
        instance.send(name, *args, &block)
      end
  end
  
  # Initializes a new settings object. You can initialize an object in any of the following ways:
  #
  #   Settings.new(:application) # will look for config/application.yml
  #   Settings.new("application.yaml") # will look for application.yaml
  #   Settings.new("/var/configs/application.yml") # will look for /var/configs/application.yml
  #   Settings.new(:config1 => 1, :config2 => 2)
  #
  # Basically if you pass a symbol it will look for that file in the configs directory of your rails app, if you are using this in rails. If you pass a string it should be an absolute path to your settings file.
  # Then you can pass a hash, and it just allows you to access the hash via methods.
  def initialize(hash_or_file = self.class.source)
    case hash_or_file
    when Hash
      self.update hash_or_file
    else
      hash = YAML.load(ERB.new(File.read(hash_or_file)).result).to_hash
      hash = hash[self.class.namespace] if self.class.namespace
      self.update hash
    end
  end
  
  module EigenMethodDefiner
    def method_missing(name, *args, &block)
      if key?(name.to_s)
        define_eigen_method name.to_s
        value = self[name.to_s]
        value.extend EigenMethodDefiner if value.is_a? Hash
        value
      else
        super
      end
    end

    private

      def define_eigen_method(name)
        eigen_class = class << self; self; end
        eigen_class.send(:define_method, name) { self[name] }
      end
  end

  include EigenMethodDefiner
end

{'fraction_non_alphanumeric': 0.07930660888407368, 'fraction_numerical': 0.001733477789815818, 'mean_word_length': 2.374269005847953, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, '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': '7017418', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1385, 'n_words': 453}