Class: Deploy::CLI::WebsocketClient::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy/cli/websocket_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#exchangeObject (readonly)

Returns the value of attribute exchange.



16
17
18
# File 'lib/deploy/cli/websocket_client.rb', line 16

def exchange
  @exchange
end

#routing_keyObject (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

Returns:

  • (Boolean)


38
39
40
# File 'lib/deploy/cli/websocket_client.rb', line 38

def subscribed?
  @subscribed == true
end