Skip to content

Commit c2c8205

Browse files
committed
Add set: request mutator sugar
1 parent 7564f96 commit c2c8205

File tree

8 files changed

+147
-42
lines changed

8 files changed

+147
-42
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.1.3] - 2026-01-21
2+
3+
- Add `set:` request mutator sugar
4+
15
## [1.1.2] - 2025-12-18
26

37
- Fix bug causing commands to cram together on help page

Gemfile.lock

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
foobara-http-command-connector (1.1.2)
4+
foobara-http-command-connector (1.1.3)
55
foobara (>= 0.1.1, < 2.0.0)
66

77
GEM
@@ -12,7 +12,8 @@ GEM
1212
ast (2.4.3)
1313
base64 (0.3.0)
1414
bigdecimal (4.0.1)
15-
byebug (12.0.0)
15+
byebug (13.0.0)
16+
reline (>= 0.6.0)
1617
coderay (1.1.3)
1718
crack (1.0.1)
1819
bigdecimal
@@ -25,25 +26,24 @@ GEM
2526
extract-repo (1.0.0)
2627
foobara (< 2.0.0)
2728
foobara-sh-cli-connector (< 2.0.0)
28-
ffi (1.17.2)
29-
ffi (1.17.2-aarch64-linux-gnu)
30-
ffi (1.17.2-aarch64-linux-musl)
31-
ffi (1.17.2-arm-linux-gnu)
32-
ffi (1.17.2-arm-linux-musl)
33-
ffi (1.17.2-arm64-darwin)
34-
ffi (1.17.2-x86-linux-gnu)
35-
ffi (1.17.2-x86-linux-musl)
36-
ffi (1.17.2-x86_64-darwin)
37-
ffi (1.17.2-x86_64-linux-gnu)
38-
ffi (1.17.2-x86_64-linux-musl)
39-
foob (0.1.1)
29+
ffi (1.17.3)
30+
ffi (1.17.3-aarch64-linux-gnu)
31+
ffi (1.17.3-aarch64-linux-musl)
32+
ffi (1.17.3-arm-linux-gnu)
33+
ffi (1.17.3-arm-linux-musl)
34+
ffi (1.17.3-arm64-darwin)
35+
ffi (1.17.3-x86-linux-gnu)
36+
ffi (1.17.3-x86-linux-musl)
37+
ffi (1.17.3-x86_64-darwin)
38+
ffi (1.17.3-x86_64-linux-gnu)
39+
ffi (1.17.3-x86_64-linux-musl)
40+
foob (0.1.2)
4041
foobara (>= 0.3.0, < 2.0.0)
4142
foobara-command-generator (< 2.0.0)
4243
foobara-domain-generator (< 2.0.0)
4344
foobara-domain-mapper-generator (< 2.0.0)
4445
foobara-empty-ruby-project-generator (< 2.0.0)
4546
foobara-empty-typescript-react-project-generator (< 2.0.0)
46-
foobara-foobify-rails-app (< 2.0.0)
4747
foobara-local-files-crud-driver-generator (< 2.0.0)
4848
foobara-mcp-connector-generator (< 2.0.0)
4949
foobara-organization-generator (< 2.0.0)
@@ -57,7 +57,8 @@ GEM
5757
foobara-type-generator (< 2.0.0)
5858
foobara-typescript-react-command-form-generator (< 2.0.0)
5959
foobara-typescript-remote-command-generator (< 2.0.0)
60-
foobara (0.4.1)
60+
foobify-rails-app (< 2.0.0)
61+
foobara (0.4.4)
6162
bigdecimal
6263
foobara-lru-cache (< 2.0.0)
6364
foobara-util (< 2.0.0)
@@ -82,8 +83,6 @@ GEM
8283
foobara-files-generator (< 2.0.0)
8384
foobara-files-generator (0.1.1)
8485
foobara (>= 0.1.1, < 2.0.0)
85-
foobara-foobify-rails-app (0.0.8)
86-
foobara (>= 0.3.0, < 2.0.0)
8786
foobara-local-files-crud-driver-generator (0.0.3)
8887
foobara
8988
foobara-files-generator
@@ -108,7 +107,7 @@ GEM
108107
foobara-resque-scheduler-connector-generator (0.0.2)
109108
foobara
110109
foobara-files-generator
111-
foobara-rubocop-rules (1.0.10)
110+
foobara-rubocop-rules (1.0.11)
112111
rubocop
113112
rubocop-rspec
114113
foobara-sh-cli-connector (1.1.3)
@@ -124,20 +123,21 @@ GEM
124123
foobara-typescript-react-command-form-generator (1.1.1)
125124
foobara (>= 0.1.1, < 2.0.0)
126125
foobara-typescript-remote-command-generator (< 2.0.0)
127-
foobara-typescript-remote-command-generator (1.2.0)
126+
foobara-typescript-remote-command-generator (1.2.1)
128127
foobara (>= 0.1.16, < 2.0.0)
129128
foobara-files-generator (< 2.0.0)
130-
foobara-util (1.0.6)
129+
foobara-util (1.0.7)
130+
foobify-rails-app (0.0.10)
131+
foobara (>= 0.3.0, < 2.0.0)
131132
formatador (1.2.3)
132133
reline
133-
guard (2.19.1)
134+
guard (2.20.0)
134135
formatador (>= 0.2.4)
135136
listen (>= 2.7, < 4.0)
136137
logger (~> 1.6)
137138
lumberjack (>= 1.0.12, < 2.0)
138139
nenv (~> 0.1)
139140
notiffany (~> 0.0)
140-
ostruct (~> 0.6)
141141
pry (>= 0.13.0)
142142
shellany (~> 0.0)
143143
thor (>= 0.18.1)
@@ -156,7 +156,8 @@ GEM
156156
json (2.18.0)
157157
language_server-protocol (3.17.0.5)
158158
lint_roller (1.1.0)
159-
listen (3.9.0)
159+
listen (3.10.0)
160+
logger
160161
rb-fsevent (~> 0.10, >= 0.10.3)
161162
rb-inotify (~> 0.9, >= 0.9.10)
162163
logger (1.7.0)
@@ -166,32 +167,32 @@ GEM
166167
notiffany (0.1.3)
167168
nenv (~> 0.1)
168169
shellany (~> 0.0)
169-
ostruct (0.6.3)
170170
parallel (1.27.0)
171-
parser (3.3.10.0)
171+
parser (3.3.10.1)
172172
ast (~> 2.4.1)
173173
racc
174174
pp (0.6.3)
175175
prettyprint
176176
prettyprint (0.2.0)
177-
prism (1.7.0)
178-
pry (0.15.2)
177+
prism (1.8.0)
178+
pry (0.16.0)
179179
coderay (~> 1.1)
180180
method_source (~> 1.0)
181-
pry-byebug (3.11.0)
182-
byebug (~> 12.0)
183-
pry (>= 0.13, < 0.16)
181+
reline (>= 0.6.0)
182+
pry-byebug (3.12.0)
183+
byebug (~> 13.0)
184+
pry (>= 0.13, < 0.17)
184185
psych (5.3.1)
185186
date
186187
stringio
187-
public_suffix (7.0.0)
188+
public_suffix (7.0.2)
188189
racc (1.8.1)
189190
rainbow (3.1.1)
190191
rake (13.3.1)
191192
rb-fsevent (0.11.2)
192193
rb-inotify (0.11.1)
193194
ffi (~> 1.0)
194-
rdoc (7.0.1)
195+
rdoc (7.1.0)
195196
erb
196197
psych (>= 4.0.0)
197198
tsort
@@ -215,7 +216,7 @@ GEM
215216
diff-lcs (>= 1.2.0, < 2.0)
216217
rspec-support (~> 3.13.0)
217218
rspec-support (3.13.6)
218-
rubocop (1.82.0)
219+
rubocop (1.82.1)
219220
json (~> 2.3)
220221
language_server-protocol (~> 3.17.0.2)
221222
lint_roller (~> 1.1.0)
@@ -226,13 +227,13 @@ GEM
226227
rubocop-ast (>= 1.48.0, < 2.0)
227228
ruby-progressbar (~> 1.7)
228229
unicode-display_width (>= 2.4.0, < 4.0)
229-
rubocop-ast (1.48.0)
230+
rubocop-ast (1.49.0)
230231
parser (>= 3.3.7.2)
231-
prism (~> 1.4)
232+
prism (~> 1.7)
232233
rubocop-rake (0.7.1)
233234
lint_roller (~> 1.1)
234235
rubocop (>= 1.72.1)
235-
rubocop-rspec (3.8.0)
236+
rubocop-rspec (3.9.0)
236237
lint_roller (~> 1.1)
237238
rubocop (~> 1.81)
238239
ruby-prof (1.7.2)
@@ -246,13 +247,12 @@ GEM
246247
simplecov-html (0.13.2)
247248
simplecov_json_formatter (0.1.4)
248249
stringio (3.2.0)
249-
thor (1.4.0)
250+
thor (1.5.0)
250251
tsort (0.2.0)
251252
unicode-display_width (3.2.0)
252253
unicode-emoji (~> 4.1)
253254
unicode-emoji (4.2.0)
254-
vcr (6.3.1)
255-
base64
255+
vcr (6.4.0)
256256
webmock (3.26.1)
257257
addressable (>= 2.8.0)
258258
crack (>= 0.3.2)

lib/foobara/http_command_connector.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,15 @@
22
require "foobara/command_connectors"
33

44
Foobara::Util.require_directory "#{__dir__}/../../src"
5+
6+
module Foobara
7+
module HttpCommandConnector
8+
class << self
9+
def install!
10+
CommandConnector.add_desugarizer CommandConnectors::Http::Desugarizers::SetInputToProcResult
11+
end
12+
end
13+
end
14+
15+
project "http_command_connector", project_path: "#{__dir__}/../../"
16+
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
RSpec.describe Foobara::CommandConnectors::Http::Desugarizers::SetInputToProcResult do
2+
let(:command_class) do
3+
stub_class(:SomeCommand, Foobara::Command) do
4+
inputs foo: :string, bar: :string
5+
result :duck
6+
def execute = inputs
7+
end
8+
end
9+
10+
let(:some_foo) { "Fooooooo" }
11+
12+
let(:command_connector) { Foobara::CommandConnectors::Http.new }
13+
let(:response) { command_connector.run(path:, query_string:) }
14+
let(:query_string) { "bar=barvalue" }
15+
let(:path) { "/run/#{command_class.full_command_name}" }
16+
17+
before do
18+
foo = some_foo
19+
command_connector.connect(command_class, request: { set: { foo: -> { foo } } })
20+
end
21+
22+
it "sets the input to the expected value" do
23+
expect(response.status).to eq(200)
24+
expect(JSON.parse(response.body)).to eq("bar" => "barvalue", "foo" => "Fooooooo")
25+
end
26+
27+
it "makes changes in the manifest" do
28+
manifest = command_connector.foobara_manifest
29+
30+
expect(manifest[:command][:SomeCommand][:inputs_type]).to eq(
31+
type: :attributes,
32+
element_type_declarations: {
33+
bar: :string
34+
}
35+
)
36+
end
37+
end

spec/foobara/command_connectors_http/set_input_to_proc_result_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def execute
2626
command_connector.connect(command_class, request_mutators: request_mutator)
2727
end
2828

29-
it "moves the cookie to an input" do
29+
it "sets the input to the expected value" do
3030
expect(response.status).to eq(200)
3131
expect(JSON.parse(response.body)).to eq("bar" => "barvalue", "foo" => "Fooooooo")
3232
end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module Foobara
2+
module CommandConnectors
3+
class Http < CommandConnector
4+
module Desugarizers
5+
class SetInputToProcResult < Desugarizer
6+
def applicable?(args_and_opts)
7+
_args, opts = args_and_opts
8+
9+
return false unless opts.key?(:request_mutators)
10+
11+
mutators = opts[:request_mutators]
12+
mutators = Util.array(mutators)
13+
14+
mutators.any? do |mutator|
15+
mutator.is_a?(::Hash) && mutator.key?(:set)
16+
end
17+
end
18+
19+
def desugarize(args_and_opts)
20+
args, opts = args_and_opts
21+
22+
mutators = opts[:request_mutators]
23+
resulting_mutators = []
24+
25+
Util.array(mutators).map do |mutator|
26+
if mutator.is_a?(::Hash) && mutator.key?(:set)
27+
if mutator.size > 1
28+
# TODO: add test for this
29+
# :nocov:
30+
resulting_mutators << mutator.except(:set)
31+
# :nocov:
32+
end
33+
34+
mutator[:set].each_pair do |input_name, proc|
35+
resulting_mutators << Http::SetInputToProcResult.for(input_name, &proc)
36+
end
37+
else
38+
# TODO: add a test for this
39+
# :nocov:
40+
resulting_mutators << mutator
41+
# :nocov:
42+
end
43+
end
44+
45+
[args, opts.merge(request_mutators: resulting_mutators)]
46+
end
47+
end
48+
end
49+
end
50+
end
51+
end

src/http/request_mutators/set_input_to_proc_result.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module CommandConnectors
33
class Http < CommandConnector
44
# TODO: We don't really want to mutate the request. We just need access to the authenticated user.
55
# consider changing inputs transformer to have access to the command/request somehow
6+
# TODO: what does this have to do with HTTP? Shouldn't this be a generic mutator for all connectors?
67
class SetInputToProcResult < RequestMutator
78
class << self
89
attr_accessor :attribute_name, :input_value_proc

version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Foobara
22
module HttpCommandConnector
3-
VERSION = "1.1.2".freeze
3+
VERSION = "1.1.3".freeze
44
MINIMUM_RUBY_VERSION = ">= 3.4.0".freeze
55
end
66
end

0 commit comments

Comments
 (0)