Class: Dev::Port

Inherits:
Object show all
Defined in:
lib/firespring_dev_commands/port.rb

Overview

Class containing methods for actions to be taken on ports

Instance Attribute Summary collapse

Instance Method Summary collapse

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_addressObject

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

#portObject

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

Returns:

  • (Boolean)


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