<commit_before># encoding: UTF-8
require 'fileutils'

module Earthquake
  module Core
    def config
      @config ||= {}
    end

    def preferred_config
      @preferred_config ||= {}
    end

    def item_queue
      @item_queue ||= []
    end

    def inits
      @inits ||= []
    end

    def init(&block)
      inits << block
    end

    def onces
      @once ||= []
    end

    def once(&block)
      onces << block
    end

    def _once
      onces.each { |block| class_eval(&block) }
    end

    def _init
      load_config
      load_plugins
      inits.each { |block| class_eval(&block) }
      inits.clear
    end

    def reload
      Gem.refresh
      loaded = ActiveSupport::Dependencies.loaded.dup
      ActiveSupport::Dependencies.clear
      loaded.each { |lib| require_dependency lib }
    rescue Exception => e
      error e
    ensure
      _init
    end

    def default_config
      consumer = YAML.load_file(File.expand_path('../../../consumer.yml', __FILE__))
      dir = File.expand_path('~/.earthquake')
      {
        dir:             dir,
        time_format:     Time::DATE_FORMATS[:short],
        plugin_dir:      File.join(dir, 'plugin'),
        file:            File.join(dir, 'config'),
        prompt:          '⚡ ',
        consumer_key:    consumer['key'],
        consumer_secret: consumer['secret'],
        output_interval: 1,
        history_size:    1000,
        api:             { :host => 'userstream.twitter.com', :path => '/2/user.json', :ssl => true },
        confirm_type:    :y,
        expand_url:      false,
        thread_indent:   "  ",
      }
    end

    def load_config
      config.reverse_update(default_config)

      [config[:dir], config[:plugin_dir]].each do |dir|
        unless File.exists?(dir)
          FileUtils.mkdir_p(dir)
        end
      end<commit_msg>respect config[:dir] as a default config (fixes #124)<commit_after># encoding: UTF-8
require 'fileutils'

module Earthquake
  module Core
    def config
      @config ||= {}
    end

    def preferred_config
      @preferred_config ||= {}
    end

    def item_queue
      @item_queue ||= []
    end

    def inits
      @inits ||= []
    end

    def init(&block)
      inits << block
    end

    def onces
      @once ||= []
    end

    def once(&block)
      onces << block
    end

    def _once
      onces.each { |block| class_eval(&block) }
    end

    def _init
      load_config
      load_plugins
      inits.each { |block| class_eval(&block) }
      inits.clear
    end

    def reload
      Gem.refresh
      loaded = ActiveSupport::Dependencies.loaded.dup
      ActiveSupport::Dependencies.clear
      loaded.each { |lib| require_dependency lib }
    rescue Exception => e
      error e
    ensure
      _init
    end

    def default_config
      consumer = YAML.load_file(File.expand_path('../../../consumer.yml', __FILE__))
      dir = config[:dir] || File.expand_path('~/.earthquake')
      {
        dir:             dir,
        time_format:     Time::DATE_FORMATS[:short],
        plugin_dir:      File.join(dir, 'plugin'),
        file:            File.join(dir, 'config'),
        prompt:          '⚡ ',
        consumer_key:    consumer['key'],
        consumer_secret: consumer['secret'],
        output_interval: 1,
        history_size:    1000,
        api:             { :host => 'userstream.twitter.com', :path => '/2/user.json', :ssl => true },
        confirm_type:    :y,
        expand_url:      false,
        thread_indent:   "  ",
      }
    end

    def load_config
      config.reverse_update(default_config)

      [config[:dir], config[:plugin_dir]].each do |dir|
        unless File.exists?(dir)
          FileUtils.mkdir_p(dir)
        end
      end
{'fraction_non_alphanumeric': 0.11703267273701125, 'fraction_numerical': 0.0045527584359935725, 'mean_word_length': 1.8295454545454546, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4516296', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1136, 'n_words': 255}