<commit_before>require "zconfig/setup"
require "zconfig/watcher"
require "yaml"

module ZConfig
  class Error < StandardError; end

  def self.config
    @config ||= {}
  end

  def self.get(*args)
    # TODO: this lookup logic is hard to read
    config_name, lookup_path = args.map(&:to_s)
    load(config_name) unless config[config_name]

    unless lookup_path
      config[config_name]
    else
      config[config_name].fetch(lookup_path, nil) if config[config_name]
    end
  end

  def self.reset!
    @config, @setup = nil
  end

  def self.setup
    if block_given?
      @setup = Setup.new
      yield @setup
    else
      raise Error, "ZConfig hasn't been setup!" unless @setup
      @setup
    end
  end

  def self.watch!
    watcher = Watcher.new(setup.active_path)
    watcher.on_event do |event, _, filename|
      ZConfig.load_file(filename) if filename.end_with?(".yml")
    end
    at_exit { watcher.stop }
    watcher.start
  end

  private

  def self.load(config_name)
    load_file("#{config_name}.yml")
  end

  def self.load_file(filename)
    path = File.join(setup.active_path, filename)
    if File.exists?(path)
      config[filename[0..-5]] = YAML.load(File.read(path))
    end
  end
end<commit_msg>private module methods aren't a thing<commit_after>require "zconfig/setup"
require "zconfig/watcher"
require "yaml"

module ZConfig
  class Error < StandardError; end

  def self.config
    @config ||= {}
  end

  def self.get(*args)
    # TODO: this lookup logic is hard to read
    config_name, lookup_path = args.map(&:to_s)
    load(config_name) unless config[config_name]

    unless lookup_path
      config[config_name]
    else
      config[config_name].fetch(lookup_path, nil) if config[config_name]
    end
  end

  def self.reset!
    @config, @setup = nil
  end

  def self.setup
    if block_given?
      @setup = Setup.new
      yield @setup
    else
      raise Error, "ZConfig hasn't been setup!" unless @setup
      @setup
    end
  end

  def self.watch!
    watcher = Watcher.new(setup.active_path)
    watcher.on_event do |event, _, filename|
      ZConfig.load_file(filename) if filename.end_with?(".yml")
    end
    at_exit { watcher.stop }
    watcher.start
  end

  private # of course, this doesn't do anything

  def self.load(config_name)
    load_file("#{config_name}.yml")
  end

  def self.load_file(filename)
    path = File.join(setup.active_path, filename)
    if File.exists?(path)
      config[filename[0..-5]] = YAML.load(File.read(path))
    end
  end
end
{'fraction_non_alphanumeric': 0.1045958795562599, 'fraction_numerical': 0.001584786053882726, 'mean_word_length': 2.963893249607535, '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': '6223022', 'n_tokens_mistral': 872, 'n_tokens_neox': 843, 'n_words': 212}