Skip to content

Commit 834e5c5

Browse files
committed
Add SetInputToProcResult request mutator
1 parent a553a82 commit 834e5c5

File tree

5 files changed

+97
-8
lines changed

5 files changed

+97
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.0.25] - 2025-05-01
2+
3+
- Add SetInputToProcResult request transformer
4+
15
## [0.0.24] - 2025-04-28
26

37
- Make sure cookies are looked up by string not symbol

Gemfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
foobara-http-command-connector (0.0.24)
4+
foobara-http-command-connector (0.0.25)
55
foobara (~> 0.0.88)
66

77
GEM
@@ -55,7 +55,7 @@ GEM
5555
foobara-type-generator (~> 0.0.1)
5656
foobara-typescript-react-command-form-generator (~> 0.0.1)
5757
foobara-typescript-remote-command-generator (~> 0.0.1)
58-
foobara (0.0.113)
58+
foobara (0.0.115)
5959
bigdecimal
6060
foobara-lru-cache (~> 0.0.2)
6161
foobara-util (~> 0.0.11)
@@ -172,10 +172,10 @@ GEM
172172
pry-byebug (3.11.0)
173173
byebug (~> 12.0)
174174
pry (>= 0.13, < 0.16)
175-
psych (5.2.3)
175+
psych (5.2.4)
176176
date
177177
stringio
178-
public_suffix (6.0.1)
178+
public_suffix (6.0.2)
179179
racc (1.8.1)
180180
rainbow (3.1.1)
181181
rake (13.2.1)
@@ -194,16 +194,16 @@ GEM
194194
rspec-mocks (~> 3.13.0)
195195
rspec-core (3.13.3)
196196
rspec-support (~> 3.13.0)
197-
rspec-expectations (3.13.3)
197+
rspec-expectations (3.13.4)
198198
diff-lcs (>= 1.2.0, < 2.0)
199199
rspec-support (~> 3.13.0)
200200
rspec-its (2.0.0)
201201
rspec-core (>= 3.13.0)
202202
rspec-expectations (>= 3.13.0)
203-
rspec-mocks (3.13.2)
203+
rspec-mocks (3.13.3)
204204
diff-lcs (>= 1.2.0, < 2.0)
205205
rspec-support (~> 3.13.0)
206-
rspec-support (3.13.2)
206+
rspec-support (3.13.3)
207207
rubocop (1.75.4)
208208
json (~> 2.3)
209209
language_server-protocol (~> 3.17.0.2)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
RSpec.describe Foobara::CommandConnectors::Http::SetInputToProcResult do
2+
let(:command_class) do
3+
stub_class(:SomeCommand, Foobara::Command) do
4+
inputs foo: :string, bar: :string
5+
result :duck
6+
7+
def execute
8+
inputs
9+
end
10+
end
11+
end
12+
13+
let(:some_foo) { "Fooooooo" }
14+
15+
let(:request_mutator) do
16+
foo = some_foo
17+
described_class.for(:foo) { foo }
18+
end
19+
20+
let(:command_connector) { Foobara::CommandConnectors::Http.new }
21+
let(:response) { command_connector.run(path:, query_string:) }
22+
let(:query_string) { "bar=barvalue" }
23+
let(:path) { "/run/#{command_class.full_command_name}" }
24+
25+
before do
26+
command_connector.connect(command_class, request_mutators: request_mutator)
27+
end
28+
29+
it "moves the cookie to an input" do
30+
expect(response.status).to eq(200)
31+
expect(JSON.parse(response.body)).to eq("bar" => "barvalue", "foo" => "Fooooooo")
32+
end
33+
34+
it "makes changes in the manifest" do
35+
manifest = command_connector.foobara_manifest
36+
37+
expect(manifest[:command][:SomeCommand][:inputs_type]).to eq(
38+
type: :attributes,
39+
element_type_declarations: {
40+
bar: { type: :string }
41+
}
42+
)
43+
end
44+
end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module Foobara
2+
module CommandConnectors
3+
class Http < CommandConnector
4+
# TODO: We don't really want to mutate the request. We just need access to the authenticated user.
5+
# consider changing inputs transformer to have access to the command/request somehow
6+
class SetInputToProcResult < RequestMutator
7+
class << self
8+
attr_accessor :attribute_name, :input_value_proc
9+
10+
def for(attribute_name, &input_value_proc)
11+
subclass = Class.new(self)
12+
13+
subclass.attribute_name = attribute_name
14+
subclass.input_value_proc = input_value_proc
15+
16+
subclass
17+
end
18+
end
19+
20+
attr_writer :attribute_name, :input_value_proc
21+
22+
def inputs_type_from(inputs_type)
23+
new_declaration = TypeDeclarations::Attributes.reject(inputs_type.declaration_data, attribute_name)
24+
Domain.current.foobara_type_from_declaration(new_declaration)
25+
end
26+
27+
def mutate(request)
28+
request.inputs[attribute_name] = request.instance_exec(&input_value_proc)
29+
end
30+
31+
def attribute_name
32+
@attribute_name ||= self.class.attribute_name
33+
end
34+
35+
def input_value_proc
36+
@input_value_proc ||= self.class.input_value_proc
37+
end
38+
end
39+
end
40+
end
41+
end

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 = "0.0.24".freeze
3+
VERSION = "0.0.25".freeze
44

55
local_ruby_version = File.read("#{__dir__}/.ruby-version").chomp
66
local_ruby_version_minor = local_ruby_version[/\A(\d+\.\d+)\.\d+\z/, 1]

0 commit comments

Comments
 (0)