Class: HoptoadZmqNotifier::Configuration
- Inherits:
-
Object
- Object
- HoptoadZmqNotifier::Configuration
- Defined in:
- lib/hoptoad_zmq_notifier/configuration.rb
Overview
Used to set up and modify settings for the notifier.
Constant Summary collapse
- OPTIONS =
[:mailbox_size, :uri].freeze
Instance Attribute Summary collapse
-
#mailbox_size ⇒ Object
Size of outgoing messages queue.
-
#uri ⇒ Object
The uri to connect to (0MQ socket).
Instance Method Summary collapse
-
#[](option) ⇒ Object
Allows config options to be read like a hash.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with
hash
. - #socket ⇒ Object
-
#to_hash ⇒ Object
Returns a hash of all configurable options.
- #zmq_context ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
14 15 16 |
# File 'lib/hoptoad_zmq_notifier/configuration.rb', line 14 def initialize @mailbox_size = 200 end |
Instance Attribute Details
#mailbox_size ⇒ Object
Size of outgoing messages queue. All messages over this value will be dropped.
9 10 11 |
# File 'lib/hoptoad_zmq_notifier/configuration.rb', line 9 def mailbox_size @mailbox_size end |
#uri ⇒ Object
The uri to connect to (0MQ socket)
12 13 14 |
# File 'lib/hoptoad_zmq_notifier/configuration.rb', line 12 def uri @uri end |
Instance Method Details
#[](option) ⇒ Object
Allows config options to be read like a hash
35 36 37 |
# File 'lib/hoptoad_zmq_notifier/configuration.rb', line 35 def [](option) send(option) end |
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with hash
49 50 51 |
# File 'lib/hoptoad_zmq_notifier/configuration.rb', line 49 def merge(hash) to_hash.merge(hash) end |
#socket ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/hoptoad_zmq_notifier/configuration.rb', line 22 def socket @socket ||= begin s = zmq_context.socket ZMQ::PUB s.connect @uri s.setsockopt(ZMQ::HWM, mailbox_size) at_exit { s.close } s end end |
#to_hash ⇒ Object
Returns a hash of all configurable options
40 41 42 43 44 |
# File 'lib/hoptoad_zmq_notifier/configuration.rb', line 40 def to_hash OPTIONS.inject({}) do |hash, option| hash.merge(option.to_sym => send(option)) end end |
#zmq_context ⇒ Object
18 19 20 |
# File 'lib/hoptoad_zmq_notifier/configuration.rb', line 18 def zmq_context @zmq_context ||= ZMQ::Context.new end |