Class: Angelo::Minitest::WebsocketHelper
- Inherits:
-
Object
- Object
- Angelo::Minitest::WebsocketHelper
- Extended by:
- Forwardable
- Includes:
- Celluloid::Internals::Logger
- Defined in:
- lib/angelo/minitest/helpers.rb
Constant Summary collapse
- WS_URL =
'ws://%s:%d'
Instance Attribute Summary collapse
-
#addr ⇒ Object
writeonly
Sets the attribute addr.
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
-
#on_close ⇒ Object
writeonly
Sets the attribute on_close.
-
#on_message ⇒ Object
writeonly
Sets the attribute on_message.
-
#on_open ⇒ Object
writeonly
Sets the attribute on_open.
-
#path ⇒ Object
writeonly
Sets the attribute path.
-
#port ⇒ Object
writeonly
Sets the attribute port.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #go ⇒ Object
- #init ⇒ Object
- #init_driver ⇒ Object
- #init_socket ⇒ Object
-
#initialize(addr, port, path) ⇒ WebsocketHelper
constructor
A new instance of WebsocketHelper.
- #url ⇒ Object
Constructor Details
#initialize(addr, port, path) ⇒ WebsocketHelper
Returns a new instance of WebsocketHelper.
161 162 163 |
# File 'lib/angelo/minitest/helpers.rb', line 161 def initialize addr, port, path @addr, @port, @path = addr, port, path end |
Instance Attribute Details
#addr=(value) ⇒ Object (writeonly)
Sets the attribute addr
159 160 161 |
# File 'lib/angelo/minitest/helpers.rb', line 159 def addr=(value) @addr = value end |
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
158 159 160 |
# File 'lib/angelo/minitest/helpers.rb', line 158 def driver @driver end |
#on_close=(value) ⇒ Object (writeonly)
Sets the attribute on_close
159 160 161 |
# File 'lib/angelo/minitest/helpers.rb', line 159 def on_close=(value) @on_close = value end |
#on_message=(value) ⇒ Object (writeonly)
Sets the attribute on_message
159 160 161 |
# File 'lib/angelo/minitest/helpers.rb', line 159 def (value) @on_message = value end |
#on_open=(value) ⇒ Object (writeonly)
Sets the attribute on_open
159 160 161 |
# File 'lib/angelo/minitest/helpers.rb', line 159 def on_open=(value) @on_open = value end |
#path=(value) ⇒ Object (writeonly)
Sets the attribute path
159 160 161 |
# File 'lib/angelo/minitest/helpers.rb', line 159 def path=(value) @path = value end |
#port=(value) ⇒ Object (writeonly)
Sets the attribute port
159 160 161 |
# File 'lib/angelo/minitest/helpers.rb', line 159 def port=(value) @port = value end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
158 159 160 |
# File 'lib/angelo/minitest/helpers.rb', line 158 def socket @socket end |
Instance Method Details
#go ⇒ Object
196 197 198 199 200 201 202 203 204 |
# File 'lib/angelo/minitest/helpers.rb', line 196 def go @driver.start begin while msg = @socket.readpartial(4096) @driver.parse msg end rescue EOFError, SystemCallError => e end end |
#init ⇒ Object
165 166 167 168 |
# File 'lib/angelo/minitest/helpers.rb', line 165 def init init_socket init_driver end |
#init_driver ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/angelo/minitest/helpers.rb', line 176 def init_driver @driver = WebSocket::Driver.client self @driver.on :open do |e| @on_open.call(e) if Proc === @on_open end @driver.on :message do |e| @on_message.call(e) if Proc === @on_message end @driver.on :close do |e| @on_close.call(e) if Proc === @on_close end end |
#init_socket ⇒ Object
170 171 172 173 174 |
# File 'lib/angelo/minitest/helpers.rb', line 170 def init_socket ip = @addr ip = Socket.getaddrinfo(@addr, 'http')[0][3] unless @addr =~ /\d+\.\d+\.\d+\.\d+/ @socket = Celluloid::IO::TCPSocket.new ip, @port end |
#url ⇒ Object
192 193 194 |
# File 'lib/angelo/minitest/helpers.rb', line 192 def url WS_URL % [@addr, @port] + @path end |