Sha256: f3fa5ded8b77d9e8fa11f883c40bb38ec9e90e81ae65c073804765d1f81fb2cd

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'basquiat/support/hash_refinements'
require 'naught'
require 'erb'

module Basquiat
  DefaultLogger = Naught.build { |config| config.mimic Logger }

  class Configuration
    using HashRefinements

    attr_writer :queue_name, :exchange_name, :logger, :environment

    def queue_name
      @queue_name || 'basquiat.queue'
    end

    def exchange_name
      @exchange_name || 'basquiat.exchange'
    end

    def logger
      @logger || DefaultLogger.new
    end

    def environment
      (@environment || ENV['BASQUIAT_ENV'] || 'development').to_sym
    end

    def config_file=(path)
      load_yaml(path)
      setup_basic_options
    end

    def adapter_options
      config.fetch(:adapter_options) { Hash.new }
    end

    def default_adapter
      config.fetch(:default_adapter) { Basquiat::Adapter::Test }
    end

    def reload_classes
      Basquiat::Base.descendants.each do |klass|
        klass.reload_adapter_from_configuration
      end
    end

    private
    def config
      @yaml.fetch(environment)
    end

    def load_yaml(path)
      @yaml     = YAML.load(ERB.new(IO.readlines(path).join).result).symbolize_keys
    end

    def setup_basic_options
      @queue_name    ||= config.fetch(:queue_name) { 'basquiat.exchange' }
      @exchange_name ||= config.fetch(:exchange_name) { 'basquiat.queue' }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
basquiat-1.1.1 lib/basquiat/support/configuration.rb