foobara-http-command-connector 1.1.1 → 1.1.3
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1715bfa9cb8f787d96db3b2f527b314e9a21bc61cdb493e80db1c716c101a73d
|
|
4
|
+
data.tar.gz: 751386e288a082a533560620176b612ea8752c6fdf98ee985072e917fd45f253
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a1e22c9dec299e223eeb6ff2e79fef4b01f1f83687b213cadf42196a5887a9cdce3941030e35945216c6a5f70931fb6418c3011fea507fe0bcfbbbac561d0486
|
|
7
|
+
data.tar.gz: 2714a1040ea6857c0cdf818524b5ce0b67496a43dc421b4bd41c8cb1c0294b9762fb6cd35adfa9f6900e23b784ae2efb85b2d0d48b0c4db53781c9e5778759ce
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## [1.1.3] - 2026-01-21
|
|
2
|
+
|
|
3
|
+
- Add `set:` request mutator sugar
|
|
4
|
+
|
|
5
|
+
## [1.1.2] - 2025-12-18
|
|
6
|
+
|
|
7
|
+
- Fix bug causing commands to cram together on help page
|
|
8
|
+
- Refactor help rendering
|
|
9
|
+
- Make strings frozen-string compatible
|
|
10
|
+
|
|
1
11
|
## [1.1.1] - 2025-08-25
|
|
2
12
|
|
|
3
13
|
- Add support for including processors
|
|
@@ -2,3 +2,15 @@ require "foobara/all"
|
|
|
2
2
|
require "foobara/command_connectors"
|
|
3
3
|
|
|
4
4
|
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
|
|
@@ -70,28 +70,28 @@ module Foobara
|
|
|
70
70
|
self.manifest = manifest
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
def render_html_list(data
|
|
74
|
-
html = ""
|
|
73
|
+
def render_html_list(data)
|
|
74
|
+
html = +""
|
|
75
|
+
|
|
76
|
+
is_rendered_as_a_collection = rendered_as_collection?(data)
|
|
77
|
+
|
|
78
|
+
html << "<ul>" if is_rendered_as_a_collection
|
|
75
79
|
|
|
76
80
|
case data
|
|
77
81
|
when ::Hash
|
|
78
|
-
html << "<ul>" unless skip_wrapper
|
|
79
82
|
data.each do |key, value|
|
|
80
|
-
html <<
|
|
81
|
-
html << "<ul>"
|
|
82
|
-
html << render_html_list(value, skip_wrapper: true)
|
|
83
|
-
html << "</ul>"
|
|
84
|
-
html << "</li>"
|
|
83
|
+
html << render_list_child(value, key)
|
|
85
84
|
end
|
|
86
|
-
html << "</ul>" unless skip_wrapper
|
|
87
85
|
when ::Array
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
if is_rendered_as_a_collection
|
|
87
|
+
data.each do |item|
|
|
88
|
+
html << render_list_child(item)
|
|
89
|
+
end
|
|
90
|
+
else
|
|
91
|
+
data = data.map { |item| render_html_list(item) }
|
|
92
|
+
html << "[#{data.join(", ")}]"
|
|
91
93
|
end
|
|
92
|
-
html << "</ul>" unless skip_wrapper
|
|
93
94
|
when Manifest::Attributes
|
|
94
|
-
html << "<ul>" unless skip_wrapper
|
|
95
95
|
data.relevant_manifest.each_pair do |key, value|
|
|
96
96
|
if key.to_s == "type"
|
|
97
97
|
next
|
|
@@ -101,59 +101,77 @@ module Foobara
|
|
|
101
101
|
key = :attributes
|
|
102
102
|
value = data.attribute_declarations
|
|
103
103
|
end
|
|
104
|
-
|
|
105
|
-
html <<
|
|
106
|
-
html << render_html_list(value, skip_wrapper: true)
|
|
107
|
-
html << "</ul>"
|
|
108
|
-
html << "</li>"
|
|
104
|
+
|
|
105
|
+
html << render_list_child(value, key)
|
|
109
106
|
end
|
|
110
|
-
html << "</ul>" unless skip_wrapper
|
|
111
107
|
when Manifest::Array
|
|
112
|
-
html << "<ul>" unless skip_wrapper
|
|
113
108
|
data.relevant_manifest.each_pair do |key, value|
|
|
114
109
|
next if key == :element_type_declaration
|
|
115
110
|
|
|
116
111
|
if key.to_s == "type"
|
|
117
112
|
value = root_manifest.lookup_path(key, value)
|
|
118
113
|
end
|
|
119
|
-
html <<
|
|
120
|
-
html << "<ul>"
|
|
121
|
-
html << render_html_list(value, skip_wrapper: true)
|
|
122
|
-
html << "</ul>"
|
|
123
|
-
html << "</li>"
|
|
114
|
+
html << render_list_child(value, key)
|
|
124
115
|
end
|
|
125
|
-
|
|
126
|
-
html <<
|
|
116
|
+
|
|
117
|
+
html << render_html_list({ element_type: data.element_type })
|
|
127
118
|
when Manifest::TypeDeclaration
|
|
128
119
|
manifest = data.relevant_manifest
|
|
129
120
|
|
|
130
121
|
if manifest.is_a?(::Symbol)
|
|
131
122
|
html << foobara_reference_link(data.to_type)
|
|
132
123
|
else
|
|
133
|
-
html << "<ul>" unless skip_wrapper
|
|
134
124
|
data.relevant_manifest.each_pair do |key, value|
|
|
135
125
|
if key.to_s == "type"
|
|
136
126
|
value = root_manifest.lookup_path(key, value)
|
|
137
127
|
end
|
|
138
|
-
|
|
139
|
-
html <<
|
|
140
|
-
html << render_html_list(value, skip_wrapper: true)
|
|
141
|
-
html << "</ul>"
|
|
142
|
-
html << "</li>"
|
|
128
|
+
|
|
129
|
+
html << render_list_child(value, key)
|
|
143
130
|
end
|
|
144
|
-
html << "</ul>" unless skip_wrapper
|
|
145
131
|
end
|
|
146
132
|
when Manifest::Type, Manifest::Command, Manifest::Error
|
|
147
133
|
html << foobara_reference_link(data)
|
|
148
134
|
when Manifest::PossibleError
|
|
149
135
|
html << render_html_list(data.error)
|
|
150
136
|
else
|
|
151
|
-
html <<
|
|
137
|
+
html << case data
|
|
138
|
+
when Numeric, TrueClass, FalseClass, NilClass
|
|
139
|
+
data.inspect
|
|
140
|
+
when ::String
|
|
141
|
+
data
|
|
142
|
+
when ::Symbol, ::Time
|
|
143
|
+
data.to_s
|
|
144
|
+
else
|
|
145
|
+
# :nocov:
|
|
146
|
+
raise "Not sure how to render #{data.class}"
|
|
147
|
+
# :nocov:
|
|
148
|
+
end
|
|
152
149
|
end
|
|
153
150
|
|
|
151
|
+
html << "</ul>" if is_rendered_as_a_collection
|
|
152
|
+
|
|
154
153
|
html
|
|
155
154
|
end
|
|
156
155
|
|
|
156
|
+
def rendered_as_collection?(data)
|
|
157
|
+
if data.is_a?(::Array)
|
|
158
|
+
data.size > 5 || data.any? { |element| rendered_as_collection?(element) }
|
|
159
|
+
elsif data.is_a?(Manifest::TypeDeclaration)
|
|
160
|
+
!data.relevant_manifest.is_a?(::Symbol)
|
|
161
|
+
else
|
|
162
|
+
[
|
|
163
|
+
::Hash,
|
|
164
|
+
Manifest::Attributes,
|
|
165
|
+
Manifest::Array
|
|
166
|
+
].any? { |klass| data.is_a?(klass) }
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def render_list_child(child, label = nil)
|
|
171
|
+
label = "#{label}:" if label
|
|
172
|
+
"<li>#{label}\n#{render_html_list(child)}\n</li>"
|
|
173
|
+
end
|
|
174
|
+
|
|
157
175
|
def foobara_reference_link(manifest)
|
|
158
176
|
path = "/help/#{manifest.reference}"
|
|
159
177
|
|
|
@@ -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
|
|
@@ -3,6 +3,7 @@ module Foobara
|
|
|
3
3
|
class Http < CommandConnector
|
|
4
4
|
# TODO: We don't really want to mutate the request. We just need access to the authenticated user.
|
|
5
5
|
# 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?
|
|
6
7
|
class SetInputToProcResult < RequestMutator
|
|
7
8
|
class << self
|
|
8
9
|
attr_accessor :attribute_name, :input_value_proc
|
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
|
+
version: 1.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Miles Georgi
|
|
@@ -70,6 +70,7 @@ 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/set_input_to_proc_result.rb
|
|
73
74
|
- src/http/request.rb
|
|
74
75
|
- src/http/request_mutators/set_input_from_cookie.rb
|
|
75
76
|
- src/http/request_mutators/set_input_from_header.rb
|