<commit_before>require "gemstash"
require "dalli"
require "yaml"

module Gemstash
  #:nodoc:
  class Env
    DEFAULT_CONFIG = {
      :cache_type => "memory",
      :base_path => File.expand_path("~/.gemstash")
    }.freeze

    def self.config
      @config ||= begin
        if File.exist?(config_file)
          config = YAML.load_file(config_file)
          config = DEFAULT_CONFIG.merge(config)
          config.freeze
        else
          DEFAULT_CONFIG
        end
      end
    end

    def self.config=(value)
      reset
      @config = DEFAULT_CONFIG.merge(value).freeze
    end

    def self.default_config?(option)
      config[option] == DEFAULT_CONFIG[option]
    end

    def self.reset
      @config = nil
      @cache = nil
      @cache_client = nil
    end

    def self.min_threads
      0
    end

    def self.max_threads
      16
    end

    def self.port
      9292
    end

    def self.workers
      1
    end

    def self.pidfile
      File.join(base_dir, "puma.pid")
    end

    def self.base_dir
      File.expand_path("~/.gemstash")
    end

    def self.config_file
      File.expand_path("~/.gemstash/config.yml")
    end

    def self.rackup
      File.expand_path("../config.ru", __FILE__)
    end

    def self.cache
      @cache ||= Gemstash::Cache.new(cache_client)
    end

    def self.cache_client
      @cache_client ||= begin
        case config[:cache_type]
        when "memory"
          Gemstash::LruReduxClient.new
        when "memcached"
          Dalli::Client.new
        else
          raise "Invalid cache client: '#{config[:cache_type]}'"
        end
      end
    end

    def self.rubygems_url
      "https://www.rubygems.org"
    end
  end
end<commit_msg>Make Gemstash::Env.base_dir use the config Make most config available to yaml customization<commit_after>require "gemstash"
require "dalli"
require "yaml"

module Gemstash
  #:nodoc:
  class Env
    DEFAULT_CONFIG = {
      :cache_type => "memory",
      :base_path => File.expand_path("~/.gemstash"),
      :min_threads => 0,
      :max_threads => 16,
      :port => 9292,
      :workers => 1,
      :rubygems_url => "https://www.rubygems.org"
    }.freeze

    def self.config
      @config ||= begin
        if File.exist?(config_file)
          config = YAML.load_file(config_file)
          config = DEFAULT_CONFIG.merge(config)
          config.freeze
        else
          DEFAULT_CONFIG
        end
      end
    end

    def self.config=(value)
      reset
      @config = DEFAULT_CONFIG.merge(value).freeze
    end

    def self.default_config?(option)
      config[option] == DEFAULT_CONFIG[option]
    end

    def self.reset
      @config = nil
      @cache = nil
      @cache_client = nil
    end

    def self.min_threads
      config[:min_threads]
    end

    def self.max_threads
      config[:max_threads]
    end

    def self.port
      config[:port]
    end

    def self.workers
      config[:workers]
    end

    def self.pidfile
      File.join(base_dir, "puma.pid")
    end

    def self.base_dir
      config[:base_path]
    end

    def self.config_file
      File.expand_path("~/.gemstash/config.yml")
    end

    def self.rackup
      File.expand_path("../config.ru", __FILE__)
    end

    def self.cache
      @cache ||= Gemstash::Cache.new(cache_client)
    end

    def self.cache_client
      @cache_client ||= begin
        case config[:cache_type]
        when "memory"
          Gemstash::LruReduxClient.new
        when "memcached"
          Dalli::Client.new
        else
          raise "Invalid cache client: '#{config[:cache_type]}'"
        end
      end
    end

    def self.rubygems_url
      config[:rubygems_url]
    end
  end
end
{'fraction_non_alphanumeric': 0.09975669099756691, 'fraction_numerical': 0.004325493376588267, 'mean_word_length': 1.9718875502008033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2714666', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1183, 'n_words': 258}