foobara 0.0.93 → 0.0.95

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: 447d11c02182fce4303fe2db74bbc322e0589d51161756496b2c5d8390a26eab
4
- data.tar.gz: 3a1ce551119b74488a5fe9fc86651ab914eec93f87f1d806da8f4b58135d8de7
3
+ metadata.gz: 10cd2a997729a02fc1b6f3ea24a4694a7ec3a0e5908eb3fd37f2f90fd7e56c71
4
+ data.tar.gz: 2568a8ffbc4885f8a1edc70c4a7f41582631b0e8f55e6ff6100166814d579a8e
5
5
  SHA512:
6
- metadata.gz: cf4413d689bef2063e5a43d8c88cc8f70b3d6158f722419fb613ee4a2c13560d8fff23addd5cc34d4f18ad7c6437435d5382f205b6aa53904888354e6cb0de04
7
- data.tar.gz: 761d8e8de14d04d5ca8c2916c23ead8cc261ca8b641584083ef2cb25e9fc9a621515be5a5524d41c97b0a867d829ae8b8cd802b6935b152b9ae8ef55ec9c6944
6
+ metadata.gz: d41fffe3ecdb08e1c6366ce4bf58cf7733bebcf595f16745ef6b3cd3a1ddfa67a19934934b73aff8e225e03205c73ade43b5ee92d429ba9f1a3d832de1856667
7
+ data.tar.gz: 61dba1a73fb5cb3399b68f2a8f00586f79268495106393b3083beb505d6fecd5c896dfb74beec941e3e4d8c8521e212bc6f499889c68f28c37b56c91c10c4260
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # [0.0.95] - 2025-04-07
2
+
3
+ - Split up #run and #build_request_and_command in CommandConnector to help subclasses
4
+
5
+ # [0.0.94] - 2025-04-07
6
+
7
+ - Support capture_unknown_errors at the command connector level
8
+
1
9
  # [0.0.93] - 2025-04-06
2
10
 
3
11
  - Add delegated attributes to models
@@ -7,6 +7,7 @@ module Foobara
7
7
  attr_accessor :command,
8
8
  :error,
9
9
  :command_connector,
10
+ # Why aren't there serializers on the response?
10
11
  :serializers,
11
12
  :inputs,
12
13
  :full_command_name,
@@ -15,7 +16,7 @@ module Foobara
15
16
  attr_reader :command_class
16
17
 
17
18
  def initialize(**opts)
18
- valid_keys = %i[inputs full_command_name action]
19
+ valid_keys = %i[inputs full_command_name action serializers]
19
20
 
20
21
  invalid_keys = opts.keys - valid_keys
21
22
 
@@ -28,6 +29,7 @@ module Foobara
28
29
  self.inputs = opts[:inputs] if opts.key?(:inputs)
29
30
  self.action = opts[:action] if opts.key?(:action)
30
31
  self.full_command_name = opts[:full_command_name] if opts.key?(:full_command_name)
32
+ self.serializers = Util.array(opts[:serializers]) if opts.key?(:serializers)
31
33
  end
32
34
 
33
35
  def command_class=(klass)
@@ -74,7 +76,13 @@ module Foobara
74
76
  end
75
77
 
76
78
  def outcome
77
- command.outcome
79
+ outcome = command&.outcome
80
+
81
+ if outcome
82
+ outcome
83
+ elsif error
84
+ Outcome.error(error)
85
+ end
78
86
  end
79
87
 
80
88
  def result
@@ -11,7 +11,13 @@ module Foobara
11
11
  self.body = body
12
12
  end
13
13
 
14
- foobara_delegate :command, :error, to: :request
14
+ def command
15
+ request.command
16
+ end
17
+
18
+ def success?
19
+ request.success?
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -86,6 +86,18 @@ module Foobara
86
86
  end
87
87
  end
88
88
 
89
+ attr_accessor :command_registry, :authenticator, :capture_unknown_error
90
+
91
+ def initialize(authenticator: nil, capture_unknown_error: nil, default_serializers: nil)
92
+ self.command_registry = CommandRegistry.new(authenticator:)
93
+ self.authenticator = authenticator
94
+ self.capture_unknown_error = capture_unknown_error
95
+
96
+ Util.array(default_serializers).each do |serializer|
97
+ add_default_serializer(serializer)
98
+ end
99
+ end
100
+
89
101
  def find_builtin_command_class(command_class_name)
90
102
  self.class.find_builtin_command_class(command_class_name)
91
103
  end
@@ -104,8 +116,6 @@ module Foobara
104
116
  :all_transformed_command_classes,
105
117
  to: :command_registry
106
118
 
107
- attr_accessor :command_registry, :authenticator
108
-
109
119
  def lookup_command(name)
110
120
  command_registry.foobara_lookup_command(name)
111
121
  end
@@ -237,13 +247,11 @@ module Foobara
237
247
  end
238
248
 
239
249
  def set_response_status(response)
240
- outcome = response.request.outcome
241
- response.status = outcome.success? ? 0 : 1
250
+ response.status = response.success? ? 0 : 1
242
251
  end
243
252
 
244
253
  def set_response_body(response)
245
254
  outcome = response.request.outcome
246
- # response.body = outcome.success? ? outcome.result : outcome.error_collection
247
255
  response.body = outcome.success? ? outcome.result : outcome.error_collection
248
256
  end
249
257
 
@@ -263,15 +271,6 @@ module Foobara
263
271
  end
264
272
  end
265
273
 
266
- def initialize(authenticator: nil, default_serializers: nil)
267
- self.command_registry = CommandRegistry.new(authenticator:)
268
- self.authenticator = authenticator
269
-
270
- Util.array(default_serializers).each do |serializer|
271
- add_default_serializer(serializer)
272
- end
273
- end
274
-
275
274
  def connect_delayed(registerable_name, *args, **opts)
276
275
  delayed_connections[registerable_name] = { args:, opts: }
277
276
  end
@@ -326,24 +325,30 @@ module Foobara
326
325
  end
327
326
 
328
327
  def build_request(...)
329
- self.class::Request.new(...)
328
+ self.class::Request.new(...).tap do |request|
329
+ # TODO: feels like a smell
330
+ request.command_connector = self
331
+ end
330
332
  end
331
333
 
332
334
  # TODO: maybe introduce a Runner interface?
333
- def run(*, **)
335
+ def run(...)
334
336
  process_delayed_connections
335
337
 
336
- request, command = build_request_and_command(*, **)
338
+ request = build_request(...)
339
+
340
+ run_request(request)
341
+ end
337
342
 
338
- # TODO: feels like a smell
339
- request.command_connector = self
343
+ def run_request(request)
344
+ command = build_command(request)
340
345
 
341
346
  if command.respond_to?(:requires_authentication?) && command.requires_authentication?
342
347
  authenticate(request)
343
348
  end
344
349
 
345
350
  if command
346
- command.run
351
+ run_command(request)
347
352
  # :nocov:
348
353
  elsif !request.error
349
354
  raise "No command returned from #request_to_command"
@@ -353,6 +358,16 @@ module Foobara
353
358
  build_response(request)
354
359
  end
355
360
 
361
+ def run_command(request)
362
+ request.command.run
363
+ rescue => e
364
+ if capture_unknown_error
365
+ request.error = CommandConnector::UnknownError.new(e)
366
+ else
367
+ raise
368
+ end
369
+ end
370
+
356
371
  def authenticate(request)
357
372
  request_command = request.command
358
373
 
@@ -370,15 +385,13 @@ module Foobara
370
385
  end
371
386
  end
372
387
 
373
- def build_request_and_command(...)
374
- request = build_request(...)
375
-
388
+ def build_command(request)
376
389
  unless request.error
377
390
  command = request_to_command(request)
378
391
  request.command = command
379
392
  end
380
393
 
381
- [request, command]
394
+ command
382
395
  end
383
396
 
384
397
  def build_response(request)
@@ -113,6 +113,7 @@ module Foobara
113
113
  def transformed_command_class
114
114
  @transformed_command_class ||= if Util.all_blank_or_false?(
115
115
  [
116
+ capture_unknown_error,
116
117
  inputs_transformers,
117
118
  result_transformers,
118
119
  errors_transformers,
@@ -4,8 +4,10 @@ module Foobara
4
4
  module CommandConnectors
5
5
  module Serializers
6
6
  class ErrorsSerializer < Serializer
7
- def always_applicable?
8
- !request.outcome.success?
7
+ def applicable?(error_collection)
8
+ if request.outcome.nil? || !request.outcome.success?
9
+ error_collection.has_errors?
10
+ end
9
11
  end
10
12
 
11
13
  def serialize(error_collection)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.93
4
+ version: 0.0.95
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-06 00:00:00.000000000 Z
10
+ date: 2025-04-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal
@@ -487,7 +487,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
487
487
  - !ruby/object:Gem::Version
488
488
  version: '0'
489
489
  requirements: []
490
- rubygems_version: 3.6.6
490
+ rubygems_version: 3.6.2
491
491
  specification_version: 4
492
492
  summary: A command-centric and discoverable software framework with a focus on domain
493
493
  concepts and abstracting away integration code