Class: Ngrok::Tunnel

Inherits:
Object
  • Object
show all
Defined in:
lib/ngrok/tunnel.rb,
lib/ngrok/tunnel/version.rb

Constant Summary collapse

VERSION =
"2.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.ngrok_urlObject (readonly)

Returns the value of attribute ngrok_url.



13
14
15
# File 'lib/ngrok/tunnel.rb', line 13

def ngrok_url
  @ngrok_url
end

.ngrok_url_httpsObject (readonly)

Returns the value of attribute ngrok_url_https.



13
14
15
# File 'lib/ngrok/tunnel.rb', line 13

def ngrok_url_https
  @ngrok_url_https
end

.pidObject (readonly)

Returns the value of attribute pid.



13
14
15
# File 'lib/ngrok/tunnel.rb', line 13

def pid
  @pid
end

.statusObject (readonly)

Returns the value of attribute status.



13
14
15
# File 'lib/ngrok/tunnel.rb', line 13

def status
  @status
end

Class Method Details

.addrObject



55
56
57
# File 'lib/ngrok/tunnel.rb', line 55

def addr
  @params[:addr]
end

.authtokenObject



72
73
74
# File 'lib/ngrok/tunnel.rb', line 72

def authtoken
  @params[:authtoken]
end

.inherited(subclass) ⇒ Object



76
77
78
# File 'lib/ngrok/tunnel.rb', line 76

def inherited(subclass)
  init
end

.init(params = {}) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/ngrok/tunnel.rb', line 15

def init(params = {})
  # map old key 'port' to 'addr' to maintain backwards compatibility with versions 2.0.21 and earlier
  params[:addr] = params.delete(:port) if params.key?(:port)

  @params = {addr: 3001, timeout: 10, config: '/dev/null'}.merge(params)
  @status = :stopped unless @status
end

.logObject



64
65
66
# File 'lib/ngrok/tunnel.rb', line 64

def log
  @params[:log]
end

.portObject



59
60
61
62
# File 'lib/ngrok/tunnel.rb', line 59

def port
  return addr if addr.is_a?(Numeric)
  addr.split(":").last.to_i
end

.running?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/ngrok/tunnel.rb', line 47

def running?
  @status == :running
end

.start(params = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ngrok/tunnel.rb', line 23

def start(params = {})
  ensure_binary
  init(params)

  if stopped?
    @params[:log] = (@params[:log]) ? File.open(@params[:log], 'w+') : Tempfile.new('ngrok')
    @pid = spawn("exec ngrok http " + ngrok_exec_params)
    at_exit { Ngrok::Tunnel.stop }
    fetch_urls
  end

  @status = :running
  @ngrok_url
end

.stopObject



38
39
40
41
42
43
44
45
# File 'lib/ngrok/tunnel.rb', line 38

def stop
  if running?
    Process.kill(9, @pid)
    @ngrok_url = @ngrok_url_https = @pid = nil
    @status = :stopped
  end
  @status
end

.stopped?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/ngrok/tunnel.rb', line 51

def stopped?
  @status == :stopped
end

.subdomainObject



68
69
70
# File 'lib/ngrok/tunnel.rb', line 68

def subdomain
  @params[:subdomain]
end