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.



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

#exchangeObject (readonly)

Returns the value of attribute exchange.



11
12
13
# File 'lib/deploy/cli/websocket_client.rb', line 11

def exchange
  @exchange
end

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

Returns:

  • (Boolean)


32
33
34
# File 'lib/deploy/cli/websocket_client.rb', line 32

def subscribed?
  @subscribed == true
end