Class: Ngrok::Wrapper
- Inherits:
-
Object
- Object
- Ngrok::Wrapper
- Defined in:
- lib/ngrok/wrapper.rb,
lib/ngrok/wrapper/version.rb
Constant Summary collapse
- VERSION =
'0.2.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.
-
.params ⇒ Object
readonly
Returns the value of attribute params.
-
.pid ⇒ Object
readonly
Returns the value of attribute pid.
-
.status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
- .addr ⇒ Object
- .inherited(subclass) ⇒ Object
- .init(params = {}) ⇒ Object
- .port ⇒ Object
- .running? ⇒ Boolean
- .start(params = {}) ⇒ Object
- .stop ⇒ Object
- .stopped? ⇒ Boolean
Class Attribute Details
.ngrok_url ⇒ Object (readonly)
Returns the value of attribute ngrok_url.
15 16 17 |
# File 'lib/ngrok/wrapper.rb', line 15 def ngrok_url @ngrok_url end |
.ngrok_url_https ⇒ Object (readonly)
Returns the value of attribute ngrok_url_https.
15 16 17 |
# File 'lib/ngrok/wrapper.rb', line 15 def ngrok_url_https @ngrok_url_https end |
.params ⇒ Object (readonly)
Returns the value of attribute params.
15 16 17 |
# File 'lib/ngrok/wrapper.rb', line 15 def params @params end |
.pid ⇒ Object (readonly)
Returns the value of attribute pid.
15 16 17 |
# File 'lib/ngrok/wrapper.rb', line 15 def pid @pid end |
.status ⇒ Object (readonly)
Returns the value of attribute status.
15 16 17 |
# File 'lib/ngrok/wrapper.rb', line 15 def status @status end |
Class Method Details
.addr ⇒ Object
61 62 63 |
# File 'lib/ngrok/wrapper.rb', line 61 def addr @params[:addr] end |
.inherited(subclass) ⇒ Object
71 72 73 74 |
# File 'lib/ngrok/wrapper.rb', line 71 def inherited(subclass) super init end |
.init(params = {}) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ngrok/wrapper.rb', line 17 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 # rubocop:disable Naming/MemoizedInstanceVariableName end |
.port ⇒ Object
65 66 67 68 69 |
# File 'lib/ngrok/wrapper.rb', line 65 def port return addr if addr.is_a?(Numeric) addr.split(':').last.to_i end |
.running? ⇒ Boolean
53 54 55 |
# File 'lib/ngrok/wrapper.rb', line 53 def running? @status == :running end |
.start(params = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ngrok/wrapper.rb', line 25 def start(params = {}) ensure_binary init(params) persistent_ngrok = @params[:persistence] == true # Attempt to read the attributes of an existing process instead of starting a new process. try_params_from_running_ngrok if persistent_ngrok spawn_new_ngrok(persistent_ngrok: persistent_ngrok) if stopped? @status = :running if persistent_ngrok # Record the attributes of the new process so that it can be reused on a subsequent call. File.write(@persistence_file, { pid: @pid, ngrok_url: @ngrok_url, ngrok_url_https: @ngrok_url_https }.to_json) end @ngrok_url_https || @ngrok_url end |
.stop ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/ngrok/wrapper.rb', line 44 def stop if running? Process.kill(9, @pid) @ngrok_url = @ngrok_url_https = @pid = nil @status = :stopped end @status end |
.stopped? ⇒ Boolean
57 58 59 |
# File 'lib/ngrok/wrapper.rb', line 57 def stopped? @status == :stopped end |