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.
19 20 21 22 23 |
# File 'lib/deploy/cli/websocket_client.rb', line 19 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.
16 17 18 |
# File 'lib/deploy/cli/websocket_client.rb', line 16 def exchange @exchange end |
#routing_key ⇒ Object (readonly)
Returns the value of attribute routing_key.
17 18 19 |
# File 'lib/deploy/cli/websocket_client.rb', line 17 def routing_key @routing_key end |
Instance Method Details
#dispatch(event, payload) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/deploy/cli/websocket_client.rb', line 30 def dispatch(event, payload) return unless @events[event] @events[event].each do |block| block.call(payload) end end |
#on(event, &block) ⇒ Object
25 26 27 28 |
# File 'lib/deploy/cli/websocket_client.rb', line 25 def on(event, &block) @events[event] ||= [] @events[event] << block end |
#subscribed! ⇒ Object
42 43 44 |
# File 'lib/deploy/cli/websocket_client.rb', line 42 def subscribed! @subscribed = true end |
#subscribed? ⇒ Boolean
38 39 40 |
# File 'lib/deploy/cli/websocket_client.rb', line 38 def subscribed? @subscribed == true end |