Class: Ngrok::Tunnel
- Inherits:
-
Object
- Object
- Ngrok::Tunnel
- Defined in:
- lib/ngrok/tunnel.rb,
lib/ngrok/tunnel/version.rb
Constant Summary collapse
- VERSION =
"2.1.0"
Class Attribute Summary collapse
-
.ngrok_url ⇒ Object
readonly
Returns the value of attribute ngrok_url.
-
.ngrok_url_https ⇒ Object
readonly
Returns the value of attribute ngrok_url_https.
-
.pid ⇒ Object
readonly
Returns the value of attribute pid.
-
.status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
- .addr ⇒ Object
- .authtoken ⇒ Object
- .inherited(subclass) ⇒ Object
- .init(params = {}) ⇒ Object
- .log ⇒ Object
- .port ⇒ Object
- .running? ⇒ Boolean
- .start(params = {}) ⇒ Object
- .stop ⇒ Object
- .stopped? ⇒ Boolean
- .subdomain ⇒ Object
Class Attribute Details
.ngrok_url ⇒ Object (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_https ⇒ Object (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 |
.pid ⇒ Object (readonly)
Returns the value of attribute pid.
13 14 15 |
# File 'lib/ngrok/tunnel.rb', line 13 def pid @pid end |
.status ⇒ Object (readonly)
Returns the value of attribute status.
13 14 15 |
# File 'lib/ngrok/tunnel.rb', line 13 def status @status end |
Class Method Details
.addr ⇒ Object
55 56 57 |
# File 'lib/ngrok/tunnel.rb', line 55 def addr @params[:addr] end |
.authtoken ⇒ Object
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 |
.log ⇒ Object
64 65 66 |
# File 'lib/ngrok/tunnel.rb', line 64 def log @params[:log] end |
.port ⇒ Object
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
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 |
.stop ⇒ Object
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
51 52 53 |
# File 'lib/ngrok/tunnel.rb', line 51 def stopped? @status == :stopped end |
.subdomain ⇒ Object
68 69 70 |
# File 'lib/ngrok/tunnel.rb', line 68 def subdomain @params[:subdomain] end |