Class: OpenInEditorBridge
- Inherits:
-
Object
- Object
- OpenInEditorBridge
- Defined in:
- lib/open_in_editor_bridge.rb,
lib/open_in_editor_bridge/version.rb
Defined Under Namespace
Classes: StartupError
Constant Summary collapse
- DEFAULT_PORT =
3333- HEALTH_PATH =
"/health"- OPEN_IN_EDITOR_PATH =
"/__open-in-editor"- RESPONSE_PHRASES =
{ 200 => "OK", 400 => "Bad Request", 404 => "Not Found", 405 => "Method Not Allowed", 500 => "Internal Server Error", }.freeze
- VERSION =
"0.1.1"
Class Method Summary collapse
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(env: ENV, project_root: nil) ⇒ OpenInEditorBridge
constructor
A new instance of OpenInEditorBridge.
Constructor Details
#initialize(env: ENV, project_root: nil) ⇒ OpenInEditorBridge
Returns a new instance of OpenInEditorBridge.
49 50 51 52 |
# File 'lib/open_in_editor_bridge.rb', line 49 def initialize(env: ENV, project_root: nil) @env = env @project_root = project_root end |
Class Method Details
.call(*args) ⇒ Object
27 28 29 |
# File 'lib/open_in_editor_bridge.rb', line 27 def self.call(*args) new.call(*args) end |
.with_running(ensure_running: true) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/open_in_editor_bridge.rb', line 31 def self.with_running(ensure_running: true) owns_server = !ensure_running owns_server = call("--ensure-running") == :started if ensure_running begin yield ensure if owns_server block_error = $! begin call("--shutdown") rescue StandardError => cleanup_error raise cleanup_error unless block_error end end end end |
Instance Method Details
#call(*args) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/open_in_editor_bridge.rb', line 54 def call(*args) case args.first || "--serve" when "--ensure-running" ensure_running when "--shutdown" shutdown when "--serve" serve else serve end end |