Class: Deploy::CLI::WebsocketClient::Subscription
- Inherits:
-
Object
- Object
- Deploy::CLI::WebsocketClient::Subscription
- Defined in:
- lib/deploy/cli/websocket_client.rb
Instance Attribute Summary collapse
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#routing_key ⇒ Object
readonly
Returns the value of attribute routing_key.
Instance Method Summary collapse
- #dispatch(event, payload) ⇒ Object
-
#initialize(exchange, routing_key) ⇒ Subscription
constructor
A new instance of Subscription.
- #on(event, &block) ⇒ Object
- #subscribed! ⇒ Object
- #subscribed? ⇒ Boolean
Constructor Details
#initialize(exchange, routing_key) ⇒ Subscription
Returns a new instance of Subscription.
13 14 15 16 17 |
# File 'lib/deploy/cli/websocket_client.rb', line 13 def initialize(exchange, routing_key) @exchange = exchange @routing_key = routing_key @events = {} end |
Instance Attribute Details
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
11 12 13 |
# File 'lib/deploy/cli/websocket_client.rb', line 11 def exchange @exchange end |
#routing_key ⇒ Object (readonly)
Returns the value of attribute routing_key.
11 12 13 |
# File 'lib/deploy/cli/websocket_client.rb', line 11 def routing_key @routing_key end |
Instance Method Details
#dispatch(event, payload) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/deploy/cli/websocket_client.rb', line 24 def dispatch(event, payload) return unless @events[event] @events[event].each do |block| block.call(payload) end end |
#on(event, &block) ⇒ Object
19 20 21 22 |
# File 'lib/deploy/cli/websocket_client.rb', line 19 def on(event, &block) @events[event] ||= [] @events[event] << block end |
#subscribed! ⇒ Object
36 37 38 |
# File 'lib/deploy/cli/websocket_client.rb', line 36 def subscribed! @subscribed = true end |
#subscribed? ⇒ Boolean
32 33 34 |
# File 'lib/deploy/cli/websocket_client.rb', line 32 def subscribed? @subscribed == true end |