Class: Ngrok::Tunnel

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

Constant Summary collapse

VERSION =
"2.0.20"

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

.authtokenObject



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

def authtoken
  @params[:authtoken]
end

.inherited(subclass) ⇒ Object



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

def inherited(subclass)
  init
end

.init(params = {}) ⇒ Object



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

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

.logObject



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

def log
  @params[:log]
end

.portObject



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

def port
  @params[:port]
end

.running?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ngrok/tunnel.rb', line 44

def running?
  @status == :running
end

.start(params = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ngrok/tunnel.rb', line 20

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



35
36
37
38
39
40
41
42
# File 'lib/ngrok/tunnel.rb', line 35

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

.stopped?Boolean

Returns:

  • (Boolean)


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

def stopped?
  @status == :stopped
end

.subdomainObject



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

def subdomain
  @params[:subdomain]
end