Sha256: 6119f164fa1cc19d968560ccfd255ffb4753933614ffe5cadaca062c93a20304

Contents?: true

Size: 813 Bytes

Versions: 2

Compression:

Stored size: 813 Bytes

Contents

module ActiveHook
  class << self
    def configure
      reset
      yield(config)
    end

    def config
      @config ||= build_config
    end

    def build_config
      klass =
        case ActiveHook.mode
        when :server then ActiveHook::Server::Config
        when :client then ActiveHook::Client::Config
        else ActiveHook::App::Config
        end
      klass.new
    end

    def reset
      @config = nil
      @connection_pool = nil
    end
  end

  class BaseConfig
    BASE_DEFAULTS = {
      redis_url: ENV['REDIS_URL'],
      redis_pool: 5
    }.freeze

    attr_accessor :redis_url, :redis_pool

    def initialize
      BASE_DEFAULTS.each { |key, value| send("#{key}=", value) }
    end

    def redis
      {
        size: redis_pool,
        url: redis_url
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activehook-0.1.4 lib/activehook/config.rb
activehook-0.1.3 lib/activehook/config.rb