foobara-http-command-connector 1.1.4 → 1.1.5

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: 3aaf220de6c1bd0308c3b45a478ec95589cbf56ab99016f6459a7c1e55298f5f
4
- data.tar.gz: 63dfa67dfeaf8eb9133245c1b1d02ea85f4a03887dfcfcf52bbea4195112b999
3
+ metadata.gz: 2c289dd1ef1c2ef37cc24c81c1ec00cca419407eb98d1d78530b2c2a52e68b9c
4
+ data.tar.gz: 31760926314271b566edd1967348118ea84bb90f4c17d3cd0eb68ddfb134dc20
5
5
  SHA512:
6
- metadata.gz: 53cf0f024f69628fdafb3239474ff32000cf67c00cb3020d6cd038a9bf5e8874af2027adc529879027c452e0ad580af953bf48a4a3d094b77a3da4c795907a42
7
- data.tar.gz: baad23a7911efd4b36638f2f34ea9aa4bde97fe154c7611b0d378bea50d9575e345c2cbbfdfc512e052b7b01f60225cce9ec1ce2059cd7a37f8fe9ee6acc6617
6
+ metadata.gz: 5467bc2d13812249c07b36ab4f60d924aa0d3be9bf9e84e735b2d7ef170def548c6a7498d21f20ec2b5f39bf6e2a423e55c94784d62d4b33c07e71ff8eac01ab
7
+ data.tar.gz: 54e998d6a5b19a379a1623984ba023993e103f19fd29f123c438e7ff1af5c8dcd31e5cf5d99775c32a932b02f1c21a35f28faf8c61cf45c89f06dca9addc9b72
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [1.1.5] - 2026-02-13
2
+
3
+ - Add a DefaultInputs request mutator
4
+
1
5
  ## [1.1.4] - 2026-01-27
2
6
 
3
7
  - Make cookie options optional
@@ -8,6 +8,7 @@ module Foobara
8
8
  class << self
9
9
  def install!
10
10
  CommandConnector.add_desugarizer CommandConnectors::Http::Desugarizers::SetInputToProcResult
11
+ CommandConnector.add_desugarizer CommandConnectors::Http::Desugarizers::DefaultInputs
11
12
  end
12
13
  end
13
14
  end
@@ -0,0 +1,49 @@
1
+ module Foobara
2
+ module CommandConnectors
3
+ class Http < CommandConnector
4
+ module Desugarizers
5
+ class DefaultInputs < 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?(:default)
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?(:default)
27
+ if mutator.size > 1
28
+ # TODO: add test for this
29
+ # :nocov:
30
+ resulting_mutators << mutator.except(:default)
31
+ # :nocov:
32
+ end
33
+
34
+ resulting_mutators << Http::DefaultInputsRequestMutator.for(mutator[:default])
35
+ else
36
+ # TODO: add a test for this
37
+ # :nocov:
38
+ resulting_mutators << mutator
39
+ # :nocov:
40
+ end
41
+ end
42
+
43
+ [args, opts.merge(request_mutators: resulting_mutators)]
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,48 @@
1
+ module Foobara
2
+ module CommandConnectors
3
+ class Http < CommandConnector
4
+ # TODO: what does this have to do with HTTP? Shouldn't this be a generic mutator for all connectors?
5
+ class DefaultInputsRequestMutator < RequestMutator
6
+ class << self
7
+ attr_accessor :defaults
8
+
9
+ def for(defaults)
10
+ subclass = Class.new(self)
11
+ subclass.defaults = defaults
12
+ subclass
13
+ end
14
+ end
15
+
16
+ def inputs_type_from(inputs_type)
17
+ declaration_data = inputs_type.declaration_data
18
+ existing_defaults ||= declaration_data[:defaults] || {}
19
+ declaration_data = declaration_data.merge(defaults: existing_defaults.merge(defaults))
20
+
21
+ if declaration_data.key?(:required)
22
+ declaration_data[:required] = declaration_data[:required] - defaults.keys
23
+ end
24
+
25
+ Domain.current.foobara_type_from_declaration(declaration_data)
26
+ end
27
+
28
+ def applicable?(_request)
29
+ true
30
+ end
31
+
32
+ def mutate(request)
33
+ defaults.each_pair do |key, value|
34
+ unless request.inputs.key?(key)
35
+ request.inputs[key] = if value.is_a?(Proc)
36
+ request.instance_exec(&value)
37
+ else
38
+ value
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ def defaults = @defaults ||= self.class.defaults
45
+ end
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-http-command-connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -70,8 +70,10 @@ files:
70
70
  - src/http/commands/help/templates/root.html.erb
71
71
  - src/http/commands/help/templates/type.html.erb
72
72
  - src/http/cookie.rb
73
+ - src/http/desugarizers/default_inputs.rb
73
74
  - src/http/desugarizers/set_input_to_proc_result.rb
74
75
  - src/http/request.rb
76
+ - src/http/request_mutators/default_inputs_request_mutator.rb
75
77
  - src/http/request_mutators/set_input_from_cookie.rb
76
78
  - src/http/request_mutators/set_input_from_header.rb
77
79
  - src/http/request_mutators/set_input_to_proc_result.rb