Class: Travis::Client::Listener
- Inherits:
-
Object
- Object
- Travis::Client::Listener
show all
- Defined in:
- lib/travis/client/listener.rb
Defined Under Namespace
Classes: EntityListener, Event, Socket
Constant Summary
collapse
- EVENTS =
%w[
build:created build:started build:finished
job:created job:started job:log job:finished
]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(session) ⇒ Listener
Returns a new instance of Listener.
71
72
73
74
75
76
|
# File 'lib/travis/client/listener.rb', line 71
def initialize(session)
@session = session
@socket = Socket.new(pusher_key, pusher_options)
@channels = []
@callbacks = []
end
|
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
69
70
71
|
# File 'lib/travis/client/listener.rb', line 69
def session
@session
end
|
#socket ⇒ Object
Returns the value of attribute socket.
69
70
71
|
# File 'lib/travis/client/listener.rb', line 69
def socket
@socket
end
|
Instance Method Details
#disconnect ⇒ Object
105
106
107
|
# File 'lib/travis/client/listener.rb', line 105
def disconnect
socket.disconnect
end
|
#listen ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/travis/client/listener.rb', line 97
def listen
@channels = default_channels if @channels.empty?
@channels.map! { |c| c.start_with?('private-') ? c : "private-#{c}" } if session.private_channels?
@channels.uniq.each { |c| socket.subscribe(c) }
@callbacks.each { |e,b| socket.bind(e) { |d| dispatch(e, d, &b) } }
socket.connect
end
|
#on(*events, &block) ⇒ Object
88
89
90
91
|
# File 'lib/travis/client/listener.rb', line 88
def on(*events, &block)
events = events.flat_map { |e| e.respond_to?(:to_str) ? e.to_str : EVENTS.grep(e) }.uniq
events.each { |e| @callbacks << [e, block] }
end
|
#on_connect ⇒ Object
93
94
95
|
# File 'lib/travis/client/listener.rb', line 93
def on_connect
socket.bind('pusher:connection_established') { yield }
end
|
#subscribe(*entities) {|entities.any? ? EntityListener.new(self, entities) : self| ... } ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/travis/client/listener.rb', line 78
def subscribe(*entities)
entities = entities.map do |entity|
entity = entity.pusher_entity while entity.respond_to? :pusher_entity
@channels.concat(entity.pusher_channels)
entity
end
yield entities.any? ? EntityListener.new(self, entities) : self if block_given?
end
|