Class: Dev::Port
Overview
Class containing methods for actions to be taken on ports
Instance Attribute Summary collapse
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(ip_address, port) ⇒ Port
constructor
A new instance of Port.
-
#open?(timeout = 1) ⇒ Boolean
Returns true if the port is open Returns false otherwise.
Constructor Details
#initialize(ip_address, port) ⇒ Port
Returns a new instance of Port.
6 7 8 9 |
# File 'lib/firespring_dev_commands/port.rb', line 6 def initialize(ip_address, port) @ip_address = ip_address @port = port end |
Instance Attribute Details
#ip_address ⇒ Object
Returns the value of attribute ip_address.
4 5 6 |
# File 'lib/firespring_dev_commands/port.rb', line 4 def ip_address @ip_address end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/firespring_dev_commands/port.rb', line 4 def port @port end |
Instance Method Details
#open?(timeout = 1) ⇒ Boolean
Returns true if the port is open Returns false otherwise
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/firespring_dev_commands/port.rb', line 13 def open?(timeout = 1) Timeout.timeout(timeout) do TCPSocket.new(ip_address, port).close return true end false rescue Timeout::Error, Errno::ECONNREFUSED, Errno::EHOSTUNREACH false end |