local-development-gateway 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70776ca78ffae5950698180364c42f598368971d93dcec7a262088b9a599fde1
4
- data.tar.gz: 4fe4a0b113e7d7f6efd6a30f7d9a537fddd9b215ac5c746f22c5699d7e7a557e
3
+ metadata.gz: 6f3e2ce5cd6347553a1923006ebc26ff3ae5178e67515d6741014dc229ca115d
4
+ data.tar.gz: 3059913ab2b89ae89442c80112fc49701d31690b46c5ca62bf981042c765700f
5
5
  SHA512:
6
- metadata.gz: e6543f1423068cdf0ab5aca3215487ae1a343beea7a583c1031de21357e9d1e7f1690fd20cb9bb73748d15d01cd8c33197c610cc5230c5540f6cda94ca9831ba
7
- data.tar.gz: 5ea9608dd49f657d3ae4de5b8da00752f787b9a08da3e83651eeb6dffb92b41005b93587f97e66e2c5fe9302c1494914b0ab9bd0a6b11bddcfd621afe60e6329
6
+ metadata.gz: 6190a1c1563636f2a0a6ca2a08c8acb10c0a674e24551a01cac437a02c70c766ff7f6ec81251d10c086a08f414a43c445cff09095ff5f3a57cadab3580b880d3
7
+ data.tar.gz: 6f04fd1c800964cb0d44e65dc792116ece3fd622cfee945f8a2d49bf7e23165bff95050422e826dad0a4f1e4497d90797c417e87f6569da639c9833c7dd98ca1
data/README.md CHANGED
@@ -87,6 +87,25 @@ version declared by the gem. The `~> 0.1` constraint follows the consuming
87
87
  project's published Gemfile.
88
88
  The repository's `bin/dev` is only a thin wrapper around this executable API.
89
89
 
90
+ ### Ruby API lifecycle
91
+
92
+ Wrap a command that needs the gateway with the block-oriented helper:
93
+
94
+ ```ruby
95
+ require "local_development_gateway"
96
+
97
+ result = LocalDevelopmentGateway.with_running do
98
+ run_development_command
99
+ end
100
+ ```
101
+
102
+ The helper starts or reuses the gateway before yielding, returns the block's
103
+ result, and conditionally stops an unused gateway afterward. Cleanup also runs
104
+ when the block raises without replacing the original exception. For a shutdown
105
+ command that must not start a missing gateway, pass
106
+ `ensure_running: false`; the block still runs and unused-gateway cleanup is
107
+ attempted.
108
+
90
109
  ## Development checks
91
110
 
92
111
  Install the locked development tools with `bundle install`. Run the Ruby
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LocalDevelopmentGateway
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -94,6 +94,20 @@ module LocalDevelopmentGateway
94
94
  :stopped
95
95
  end
96
96
 
97
+ def with_running(ensure_running: true)
98
+ begin
99
+ self.ensure_running if ensure_running
100
+ yield
101
+ ensure
102
+ block_error = $!
103
+ begin
104
+ stop_if_unused
105
+ rescue StandardError => cleanup_error
106
+ raise cleanup_error unless block_error
107
+ end
108
+ end
109
+ end
110
+
97
111
  def compose(*args, capture: true)
98
112
  @runner.call(
99
113
  "compose",
@@ -275,6 +289,10 @@ module LocalDevelopmentGateway
275
289
  Client.new.ensure_running(*args)
276
290
  end
277
291
 
292
+ def with_running(ensure_running: true, &block)
293
+ Client.new.with_running(ensure_running: ensure_running, &block)
294
+ end
295
+
278
296
  def start(*args)
279
297
  ensure_running(*args)
280
298
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: local-development-gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marlen Brunner