Class: HoptoadZmqNotifier::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_sizeObject

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

#uriObject

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

Parameters:

  • option (Symbol)

    Key for a given attribute



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

Parameters:

  • hash (Hash)

    A set of configuration options that will take precedence over the defaults



49
50
51
# File 'lib/hoptoad_zmq_notifier/configuration.rb', line 49

def merge(hash)
  to_hash.merge(hash)
end

#socketObject



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_hashObject

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_contextObject



18
19
20
# File 'lib/hoptoad_zmq_notifier/configuration.rb', line 18

def zmq_context
  @zmq_context ||= ZMQ::Context.new
end