leopard 0.1.7 → 0.2.0
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 +4 -4
- data/.release-please-manifest.json +1 -1
- data/.version.txt +1 -1
- data/CHANGELOG.md +11 -0
- data/examples/echo_endpoint.rb +2 -2
- data/lib/leopard/message_wrapper.rb +4 -2
- data/lib/leopard/nats_api_server.rb +9 -6
- data/lib/leopard/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 550ad9a639b0f8caf0989990853c1ab49428f4f48c0b28a6fdc30c30d8450a03
|
4
|
+
data.tar.gz: 0b2fdc7d99a23fe156b446b724407eedb074806d989542f42af4ff63d74744c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68cc478abf3538e4d567fe170fa72340632ac056608d16aa1dc426842c2c9de3fbb6001ac8c75058a43d41558d625fbe31ad52104d54d5c33f5363b5d84d1f7e
|
7
|
+
data.tar.gz: 9b9769a6a7c5eeadc28424f530fef164cd6ed558f1fb975afbecbefb01d96c10428bf653fddf3a6840072fe02b89a6b15eee121f55e9bf5cbd01b0e56aee1a69
|
data/.version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.2.0](https://github.com/rubyists/leopard/compare/v0.1.7...v0.2.0) (2025-08-07)
|
4
|
+
|
5
|
+
|
6
|
+
### ⚠ BREAKING CHANGES
|
7
|
+
|
8
|
+
* Big move to use kwargs as the initializer for classes which include us ([#28](https://github.com/rubyists/leopard/issues/28))
|
9
|
+
|
10
|
+
### Bug Fixes
|
11
|
+
|
12
|
+
* Big move to use kwargs as the initializer for classes which include us ([#28](https://github.com/rubyists/leopard/issues/28)) ([72293b4](https://github.com/rubyists/leopard/commit/72293b434998679fe3ff2d467a6a39c11a325b5a))
|
13
|
+
|
3
14
|
## [0.1.7](https://github.com/rubyists/leopard/compare/v0.1.6...v0.1.7) (2025-08-06)
|
4
15
|
|
5
16
|
|
data/examples/echo_endpoint.rb
CHANGED
@@ -7,7 +7,7 @@ require_relative '../lib/leopard/nats_api_server'
|
|
7
7
|
class EchoService
|
8
8
|
include Rubyists::Leopard::NatsApiServer
|
9
9
|
|
10
|
-
def initialize(a_var
|
10
|
+
def initialize(a_var: 1)
|
11
11
|
logger.info "EchoService initialized with a_var: #{a_var}"
|
12
12
|
end
|
13
13
|
|
@@ -21,7 +21,7 @@ if __FILE__ == $PROGRAM_NAME
|
|
21
21
|
service_opts: {
|
22
22
|
name: 'example.echo',
|
23
23
|
version: '1.0.0',
|
24
|
-
instance_args:
|
24
|
+
instance_args: { a_var: 2 },
|
25
25
|
},
|
26
26
|
instances: 1,
|
27
27
|
)
|
@@ -10,10 +10,11 @@ module Rubyists
|
|
10
10
|
#
|
11
11
|
# @!attribute [r] data
|
12
12
|
# @return [Object] The parsed data from the NATS message.
|
13
|
+
attr_reader :raw, :data
|
13
14
|
#
|
14
|
-
# @!attribute [
|
15
|
+
# @!attribute [w] headers
|
15
16
|
# @return [Hash] The headers from the NATS message.
|
16
|
-
|
17
|
+
attr_accessor :headers
|
17
18
|
|
18
19
|
# @param nats_msg [NATS::Message] The NATS message to wrap.
|
19
20
|
def initialize(nats_msg)
|
@@ -26,6 +27,7 @@ module Rubyists
|
|
26
27
|
#
|
27
28
|
# @return [void]
|
28
29
|
def respond(payload)
|
30
|
+
raw.header = headers unless headers.empty?
|
29
31
|
raw.respond(serialize(payload))
|
30
32
|
end
|
31
33
|
|
@@ -98,6 +98,8 @@ module Rubyists
|
|
98
98
|
pool = Concurrent::FixedThreadPool.new(count)
|
99
99
|
@instance_args = opts.delete(:instance_args) || nil
|
100
100
|
logger.info "Building #{count} workers with options: #{opts.inspect}, instance_args: #{@instance_args}"
|
101
|
+
raise ArgumentError, 'instance_args must be a Hash' if @instance_args && !@instance_args.is_a?(Hash)
|
102
|
+
|
101
103
|
count.times do
|
102
104
|
pool.post { build_worker(url, opts, workers, blocking) }
|
103
105
|
end
|
@@ -106,18 +108,19 @@ module Rubyists
|
|
106
108
|
|
107
109
|
# Builds a worker instance and sets it up with the NATS server.
|
108
110
|
#
|
109
|
-
# @param
|
110
|
-
# @param
|
111
|
+
# @param nats_url [String] The URL of the NATS server.
|
112
|
+
# @param service_opts [Hash] Options for the NATS service.
|
111
113
|
# @param workers [Array] The array to store worker instances.
|
112
114
|
# @param blocking [Boolean] If true, blocks the current thread until the worker is set up.
|
113
115
|
#
|
114
116
|
# @return [void]
|
115
|
-
def build_worker(
|
116
|
-
worker = @instance_args ? new(
|
117
|
+
def build_worker(nats_url, service_opts, workers, blocking)
|
118
|
+
worker = @instance_args ? new(**@instance_args) : new
|
117
119
|
workers << worker
|
118
|
-
|
120
|
+
args = { nats_url:, service_opts: }
|
121
|
+
return worker.setup_worker!(**args) if blocking
|
119
122
|
|
120
|
-
worker.setup_worker(
|
123
|
+
worker.setup_worker(**args)
|
121
124
|
end
|
122
125
|
|
123
126
|
# Shuts down the NATS API server gracefully.
|
data/lib/leopard/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leopard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bougyman
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-08-
|
10
|
+
date: 2025-08-07 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: concurrent-ruby
|