foobara 0.5.2 → 0.5.4
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/CHANGELOG.md +10 -1
- data/projects/command_connectors/spec/command_connector_spec.rb +20 -4
- data/projects/command_connectors/src/command_connector/concerns/desugarizers.rb +6 -6
- data/projects/command_connectors/src/command_connector/no_allowed_rule_given_error.rb +6 -0
- data/projects/command_connectors/src/command_connector.rb +31 -1
- data/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a96afa4b186236cc708db3bc2a292756816db8e601a5cef7b31d0082a4a97dea
|
|
4
|
+
data.tar.gz: f184bf52340442842d0e6d9bdaa0f50a7c3a7f07421d4bb4a1c776c634703e4e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3c2fa3e1b90cc5f6f31df05683b17fef4ef7ad77c07c5af9190a603696b4470355b357f726dcef2f05dbbdf79213c56e655578a3731f9e03cd25397c4d0fb62e
|
|
7
|
+
data.tar.gz: 7b832dba231c05086a83d0a56fc799910bcee15fae5c3979eac8923d1f1bd17064d759dc9d0c0b94456400a92e2243d93b942822af16fd1b5f12b3b6c6b479e5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
# [0.5.
|
|
1
|
+
# [0.5.4] - 2026-02-16
|
|
2
|
+
|
|
3
|
+
- Fix bug where adding a desugarizer to a subclass had no effect
|
|
4
|
+
- Add support for requiring allow_if: by default
|
|
5
|
+
|
|
6
|
+
# [0.5.3] - 2026-02-12
|
|
7
|
+
|
|
8
|
+
- Allow registering an allowed rule on an instance of a connector not just its class
|
|
9
|
+
|
|
10
|
+
# [0.5.2] - 2026-02-13
|
|
2
11
|
|
|
3
12
|
- Fix bug that results in duplicate required entries when merging declarations
|
|
4
13
|
- Communicate which nested attributes are guaranteed to exist to help external generators
|
|
@@ -488,6 +488,20 @@ RSpec.describe Foobara::CommandConnector do
|
|
|
488
488
|
expect(response.body).to eq("8")
|
|
489
489
|
end
|
|
490
490
|
|
|
491
|
+
context "when requires_allowed_rule" do
|
|
492
|
+
let(:command_connector) do
|
|
493
|
+
described_class.new(
|
|
494
|
+
authenticator:,
|
|
495
|
+
default_serializers:,
|
|
496
|
+
requires_allowed_rule: true
|
|
497
|
+
)
|
|
498
|
+
end
|
|
499
|
+
|
|
500
|
+
it "gives a relevant error" do
|
|
501
|
+
expect { response }.to raise_error(Foobara::CommandConnector::NoAllowedRuleGivenError)
|
|
502
|
+
end
|
|
503
|
+
end
|
|
504
|
+
|
|
491
505
|
context "with default transformers" do
|
|
492
506
|
before do
|
|
493
507
|
identity = proc { |x| x }
|
|
@@ -2070,16 +2084,18 @@ RSpec.describe Foobara::CommandConnector do
|
|
|
2070
2084
|
end
|
|
2071
2085
|
|
|
2072
2086
|
let(:command_connector_class_d) do
|
|
2087
|
+
stub_class "CommandConnectorD", command_connector_class_c
|
|
2088
|
+
end
|
|
2089
|
+
let(:command_connector) do
|
|
2073
2090
|
rule = allowed_rule_d
|
|
2074
|
-
|
|
2091
|
+
command_connector_class_d.new(requires_allowed_rule: true) do
|
|
2075
2092
|
register_allowed_rule :d, rule
|
|
2076
2093
|
end
|
|
2077
2094
|
end
|
|
2078
|
-
let(:command_connector) { command_connector_class_d.new }
|
|
2079
2095
|
|
|
2080
2096
|
it "puts the expected allowed rules on the command connector" do
|
|
2081
2097
|
command_connector.connect(command_class, suffix: "A", allow_if: :a)
|
|
2082
|
-
command_connector.connect(command_class, suffix: "B")
|
|
2098
|
+
command_connector.connect(command_class, suffix: "B", allow_if: :always)
|
|
2083
2099
|
command_connector.connect(command_class, suffix: "C", allowed_rule: :c)
|
|
2084
2100
|
command_connector.connect(command_class, suffix: "D", allowed_rule: :d)
|
|
2085
2101
|
|
|
@@ -2089,7 +2105,7 @@ RSpec.describe Foobara::CommandConnector do
|
|
|
2089
2105
|
|
|
2090
2106
|
response = command_connector.run(full_command_name: "ComputeExponentB", action:, inputs:)
|
|
2091
2107
|
expect(response.status).to be(0)
|
|
2092
|
-
expect(response.command.allowed_rule).to
|
|
2108
|
+
expect(response.command.allowed_rule).to be(described_class.always_allowed_rule)
|
|
2093
2109
|
|
|
2094
2110
|
response = command_connector.run(full_command_name: "ComputeExponentC", action:, inputs:)
|
|
2095
2111
|
expect(response.status).to be(1)
|
|
@@ -36,13 +36,13 @@ module Foobara
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def desugarizers
|
|
39
|
-
@desugarizers
|
|
39
|
+
return @desugarizers if defined?(@desugarizers)
|
|
40
40
|
|
|
41
|
-
if superclass == Object
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
@desugarizers = if superclass == Object
|
|
42
|
+
[]
|
|
43
|
+
else
|
|
44
|
+
superclass.desugarizers.dup
|
|
45
|
+
end
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
end
|
|
@@ -178,10 +178,19 @@ module Foobara
|
|
|
178
178
|
def build_auth_mapper(to_type, &)
|
|
179
179
|
TypeDeclarations::TypedTransformer.subclass(to: to_type, &).instance
|
|
180
180
|
end
|
|
181
|
+
|
|
182
|
+
def always_allowed_rule
|
|
183
|
+
# maybe move AllowedRule to CommandConnector:: instead of
|
|
184
|
+
# CommandRegistry:: which is more of an implementation detail?
|
|
185
|
+
@always_allowed_rule ||= CommandRegistry::AllowedRule.new(
|
|
186
|
+
symbol: :always,
|
|
187
|
+
explanation: "This always passes. Used to override allowed_rule_missing."
|
|
188
|
+
) { true }
|
|
189
|
+
end
|
|
181
190
|
end
|
|
182
191
|
|
|
183
192
|
attr_accessor :command_registry, :authenticator, :capture_unknown_error, :name,
|
|
184
|
-
:auth_map
|
|
193
|
+
:auth_map, :requires_allowed_rule
|
|
185
194
|
|
|
186
195
|
def initialize(name: nil,
|
|
187
196
|
authenticator: nil,
|
|
@@ -190,6 +199,7 @@ module Foobara
|
|
|
190
199
|
default_pre_commit_transformers: nil,
|
|
191
200
|
auth_map: nil,
|
|
192
201
|
current_user: nil,
|
|
202
|
+
requires_allowed_rule: false,
|
|
193
203
|
&block)
|
|
194
204
|
authenticator = self.class.to_authenticator(authenticator)
|
|
195
205
|
|
|
@@ -214,6 +224,11 @@ module Foobara
|
|
|
214
224
|
add_default_serializer(serializer)
|
|
215
225
|
end
|
|
216
226
|
|
|
227
|
+
if requires_allowed_rule
|
|
228
|
+
self.requires_allowed_rule = requires_allowed_rule
|
|
229
|
+
register_allowed_rule(CommandConnector.always_allowed_rule)
|
|
230
|
+
end
|
|
231
|
+
|
|
217
232
|
Util.array(default_pre_commit_transformers).each do |pre_commit_transformer|
|
|
218
233
|
add_default_pre_commit_transformer(pre_commit_transformer)
|
|
219
234
|
end
|
|
@@ -227,7 +242,12 @@ module Foobara
|
|
|
227
242
|
end
|
|
228
243
|
end
|
|
229
244
|
|
|
245
|
+
def register_allowed_rule(*ruleish_args)
|
|
246
|
+
command_registry.allowed_rule(*ruleish_args)
|
|
247
|
+
end
|
|
248
|
+
|
|
230
249
|
# TODO: should this be the official way to connect a command instead of #connect ?
|
|
250
|
+
# Probably not. But what about #export instead?
|
|
231
251
|
def command(...) = connect(...)
|
|
232
252
|
|
|
233
253
|
def connect(*args, **opts)
|
|
@@ -612,6 +632,16 @@ module Foobara
|
|
|
612
632
|
def run_command(request)
|
|
613
633
|
command = request.command
|
|
614
634
|
|
|
635
|
+
if requires_allowed_rule
|
|
636
|
+
unless command.allowed_rule
|
|
637
|
+
raise NoAllowedRuleGivenError,
|
|
638
|
+
"Must connect #{command.full_command_name} with an `allowed_if:` " \
|
|
639
|
+
"because `requires_allowed_rule` is true. You can use `allow_if: :always` if want to always allow " \
|
|
640
|
+
"this command to be ran or you can also use `requires_allowed_rule: false` " \
|
|
641
|
+
"when creating the connector if you don't want to enforce allowed_if: for all connected commands."
|
|
642
|
+
end
|
|
643
|
+
end
|
|
644
|
+
|
|
615
645
|
unless command.outcome
|
|
616
646
|
command.run
|
|
617
647
|
end
|
data/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foobara
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Miles Georgi
|
|
@@ -138,6 +138,7 @@ files:
|
|
|
138
138
|
- projects/command_connectors/src/command_connector/concerns/desugarizers.rb
|
|
139
139
|
- projects/command_connectors/src/command_connector/concerns/reflection.rb
|
|
140
140
|
- projects/command_connectors/src/command_connector/invalid_context_error.rb
|
|
141
|
+
- projects/command_connectors/src/command_connector/no_allowed_rule_given_error.rb
|
|
141
142
|
- projects/command_connectors/src/command_connector/no_command_found_error.rb
|
|
142
143
|
- projects/command_connectors/src/command_connector/no_command_or_type_found_error.rb
|
|
143
144
|
- projects/command_connectors/src/command_connector/no_type_found_error.rb
|