Class: Harbour::Port

Inherits:
Object
  • Object
show all
Defined in:
lib/harbour.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port) ⇒ Port

Returns a new instance of Port.



7
8
9
# File 'lib/harbour.rb', line 7

def initialize(port)
  @port = port
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



5
6
7
# File 'lib/harbour.rb', line 5

def port
  @port
end

Instance Method Details

#kill!(options = {}) ⇒ Object



26
27
28
29
30
# File 'lib/harbour.rb', line 26

def kill!(options = {})
  return nil unless open?
  command "kill -9 #{pid}"
  ensure_open(options[:timeout] || 10)
end

#open?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/harbour.rb', line 11

def open?
  command "nc -z localhost #{port}"
end

#pidObject



15
16
17
18
# File 'lib/harbour.rb', line 15

def pid
  return nil unless open?
  `lsof -P | grep ':#{port}' | grep 'LISTEN' | awk '{print $2}'`
end

#term!(options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/harbour.rb', line 20

def term!(options = {})
  return nil unless open?
  command "kill #{pid}"
  ensure_open(options[:timeout] || 10)
end