<commit_before>module Clook
  require "clook/version"
  require "clook/configuration"

  @adapters = Hash.new { |h, k| h[k] = [] }

  class << self
    attr_writer   :configuration
    attr_accessor :adapters

    def configuration
      @configuration ||= Configuration.new
    end

    def configure
      yield(configuration) if block_given?
    end

    def load(type, *args, &block)
      require "clook/#{type.to_s}"

      @adapter = const_get("#{type.to_s.capitalize}")
      @adapter.send :initialize, *args, &block
      @adapters[type.to_sym] << @adapter

      unless @configuration.order.include? type.to_sym
        @configuration.order << type.to_sym
      end
      self
    rescue LoadError
      raise "Unknown adapter #{type}"
    end

    def fetch(stuff)
      value = nil
      @configuration.order.each do |prio|
        @adapters[prio].each do |adapter|
          value ||= adapter.fetch(stuff)
        end
      end
      value
    end

    Clook.configuration
    Clook.load("env")
  end
end<commit_msg>dynamic load<commit_after>module Clook
  require "clook/version"
  require "clook/configuration"

  @adapters = Hash.new { |h, k| h[k] = [] }

  class << self
    attr_writer   :configuration
    attr_accessor :adapters

    def configuration
      @configuration ||= Configuration.new
    end

    def configure
      yield(configuration) if block_given?
    end

    def load(type, *args, &block)
      require "clook/#{type.to_s}"

      @adapter = const_get("#{type.to_s.capitalize}")
      @adapter.send :initialize, *args, &block
      @adapters[type.to_sym] << @adapter

      unless @configuration.order.include? type.to_sym
        @configuration.order << type.to_sym
      end
      self
    rescue LoadError
      raise "Unknown adapter #{type}"
    end

    def fetch(stuff)
      value = nil
      @configuration.order.each do |prio|
        @adapters[prio].each do |adapter|
          value ||= adapter.fetch(stuff)
        end
      end
      value
    end

    def method_missing(method_sym, *args, &block)
      if method_sym.to_s =~ /^load_(\w+)$/
        Clook.load($1, *args, &block)
      else
        super
      end
    end

    Clook.configuration
    Clook.load("env")
  end
end
{'fraction_non_alphanumeric': 0.1124551971326165, 'fraction_numerical': 0.00044802867383512545, 'mean_word_length': 2.368024132730015, 'pattern_counts': {'":': 0, '<': 15, '<?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': '1295977', 'n_tokens_mistral': 730, 'n_tokens_neox': 698, 'n_words': 166}