Class: PikaQue::Configuration
- Inherits:
-
Object
- Object
- PikaQue::Configuration
- Extended by:
- Forwardable
- Defined in:
- lib/pika_que/configuration.rb
Constant Summary collapse
- EXCHANGE_OPTION_DEFAULTS =
{ :type => :direct, :durable => true, :auto_delete => false, :arguments => {} # Passed as :arguments to Bunny::Channel#exchange }.freeze
- QUEUE_OPTION_DEFAULTS =
{ :durable => true, :auto_delete => false, :exclusive => false, :arguments => {} }.freeze
- CHANNEL_OPTION_DEFAULTS =
{ :consumer_pool_size => 1, :prefetch => 10 }.freeze
- DELAY_PROCESSOR_DEFAULTS =
{ :workers => [PikaQue::DelayWorker], :handler_class => PikaQue::Handlers::DelayHandler, :concurrency => 1 }.freeze
- DEFAULT_CONFIG =
{ :exchange => 'pika-que', :heartbeat => 30, :channel_options => CHANNEL_OPTION_DEFAULTS, :exchange_options => EXCHANGE_OPTION_DEFAULTS, :queue_options => QUEUE_OPTION_DEFAULTS, :concurrency => 1, :ack => true, :handler_class => PikaQue::Handlers::DefaultHandler, :handler_options => {}, :codec => PikaQue::Codecs::JSON, :processors => [], :reporters => [], :metrics => nil, :delay => true, :delay_options => DELAY_PROCESSOR_DEFAULTS, :pidfile => nil, :require => '.' }.freeze
Instance Method Summary collapse
- #deep_merge(first, second) ⇒ Object
-
#initialize ⇒ Configuration
constructor
processor example { :processor => Processor, :connection_options => {}, :workers => [], :concurrency => 1, :ack => true, :handler_class => nil, :handler_options => {}, :codec => PikaQue::Codecs::JSON }.
- #load(filename) ⇒ Object
- #merge(other = {}) ⇒ Object
- #merge!(other = {}) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
processor example
:processor => Processor,
:connection_options => {,
:workers => [],
:concurrency => 1,
:ack => true,
:handler_class => nil,
:handler_options => {},
:codec => PikaQue::Codecs::JSON
}
79 80 81 82 83 |
# File 'lib/pika_que/configuration.rb', line 79 def initialize @config = Marshal.load(Marshal.dump(DEFAULT_CONFIG)) @config[:amqp] = ENV.fetch('RABBITMQ_URL', 'amqp://guest:guest@localhost:5672') @config[:vhost] = AMQ::Settings.parse_amqp_url(@config[:amqp]).fetch(:vhost, '/') end |
Instance Method Details
#deep_merge(first, second) ⇒ Object
102 103 104 105 |
# File 'lib/pika_que/configuration.rb', line 102 def deep_merge(first, second) merger = proc { |_, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 } first.merge(second, &merger) end |
#load(filename) ⇒ Object
85 86 87 88 89 |
# File 'lib/pika_que/configuration.rb', line 85 def load(filename) loaded = YAML.load_file(filename) converted = JSON.parse(JSON.dump(loaded), symbolize_names: true) merge! converted end |
#merge(other = {}) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/pika_que/configuration.rb', line 95 def merge(other = {}) instance = self.class.new instance.merge! to_hash instance.merge! other instance end |
#merge!(other = {}) ⇒ Object
91 92 93 |
# File 'lib/pika_que/configuration.rb', line 91 def merge!(other = {}) @config = deep_merge(@config, other) end |