foobara 0.0.9 → 0.0.11
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 +8 -0
- data/LICENSE-MPL-2.0.txt +373 -0
- data/LICENSE.txt +6 -2
- data/README.md +1 -8
- data/projects/command/src/transformed_command.rb +2 -2
- data/projects/command_connectors/lib/foobara/command_connectors.rb +1 -1
- data/projects/command_connectors/src/{commands → command_connector/commands}/describe.rb +2 -6
- data/projects/command_connectors/src/{commands → command_connector/commands}/list_commands.rb +1 -1
- data/projects/command_connectors/src/{commands → command_connector/commands}/ping.rb +1 -1
- data/projects/command_connectors/src/{commands → command_connector/commands}/query_git_commit_info.rb +1 -1
- data/projects/command_connectors/src/{request.rb → command_connector/request.rb} +24 -13
- data/projects/command_connectors/src/{response.rb → command_connector/response.rb} +1 -1
- data/projects/command_connectors/src/command_connector.rb +29 -20
- data/projects/domain/src/domain_module_extension.rb +2 -0
- data/projects/domain/src/module_extension.rb +2 -2
- metadata +11 -39
- data/LICENSE-AGPL.txt +0 -666
- data/projects/command_connectors_http/lib/foobara/command_connectors_http.rb +0 -6
- data/projects/command_connectors_http/src/http/commands/get_options.rb +0 -16
- data/projects/command_connectors_http/src/http/commands/help/presenter/command.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/domain.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/entity.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/error.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/model.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/organization.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/processor.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/processor_class.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/root.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/type.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter.rb +0 -178
- data/projects/command_connectors_http/src/http/commands/help/templates/command.html.erb +0 -11
- data/projects/command_connectors_http/src/http/commands/help/templates/domain.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help/templates/entity.html.erb +0 -11
- data/projects/command_connectors_http/src/http/commands/help/templates/error.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help/templates/model.html.erb +0 -8
- data/projects/command_connectors_http/src/http/commands/help/templates/organization.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help/templates/processor.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help/templates/processor_class.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help/templates/root.html.erb +0 -3
- data/projects/command_connectors_http/src/http/commands/help/templates/type.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help.rb +0 -98
- data/projects/command_connectors_http/src/http/request.rb +0 -98
- data/projects/command_connectors_http/src/http/response.rb +0 -14
- data/projects/command_connectors_http/src/http.rb +0 -93
@@ -1,16 +0,0 @@
|
|
1
|
-
module Foobara
|
2
|
-
module CommandConnectors
|
3
|
-
class Http < CommandConnector
|
4
|
-
module Commands
|
5
|
-
# TODO: this is a bit of a hack, just a total no-op... shouldn't really need this command at all ideally
|
6
|
-
class GetOptions < Foobara::Command
|
7
|
-
result :string
|
8
|
-
|
9
|
-
def execute
|
10
|
-
""
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,178 +0,0 @@
|
|
1
|
-
require_relative "presenter/command"
|
2
|
-
require_relative "presenter/entity"
|
3
|
-
require_relative "presenter/error"
|
4
|
-
require_relative "presenter/model"
|
5
|
-
require_relative "presenter/organization"
|
6
|
-
require_relative "presenter/domain"
|
7
|
-
require_relative "presenter/processor"
|
8
|
-
require_relative "presenter/processor_class"
|
9
|
-
require_relative "presenter/root"
|
10
|
-
require_relative "presenter/type"
|
11
|
-
|
12
|
-
module Foobara
|
13
|
-
module CommandConnectors
|
14
|
-
class Http < CommandConnector
|
15
|
-
module Commands
|
16
|
-
class Help < Command
|
17
|
-
class Presenter
|
18
|
-
class << self
|
19
|
-
def for(manifest)
|
20
|
-
case manifest
|
21
|
-
when Manifest::RootManifest
|
22
|
-
Presenter::Root
|
23
|
-
when Manifest::Command
|
24
|
-
Presenter::Command
|
25
|
-
when Manifest::Entity
|
26
|
-
Presenter::Entity
|
27
|
-
when Manifest::Model
|
28
|
-
Presenter::Model
|
29
|
-
when Manifest::Type
|
30
|
-
Presenter::Type
|
31
|
-
when Manifest::Error
|
32
|
-
Presenter::Error
|
33
|
-
when Manifest::Domain
|
34
|
-
Presenter::Domain
|
35
|
-
when Manifest::Organization
|
36
|
-
Presenter::Organization
|
37
|
-
when Manifest::Processor
|
38
|
-
Presenter::Processor
|
39
|
-
when Manifest::ProcessorClass
|
40
|
-
Presenter::ProcessorClass
|
41
|
-
else
|
42
|
-
# :nocov:
|
43
|
-
raise "No presenter found for #{manifest.path}"
|
44
|
-
# :nocov:
|
45
|
-
end.new(manifest)
|
46
|
-
end
|
47
|
-
|
48
|
-
def template_symbol
|
49
|
-
Util.underscore(Util.non_full_name(self))
|
50
|
-
end
|
51
|
-
|
52
|
-
def template_path
|
53
|
-
template_path = File.join(
|
54
|
-
__dir__,
|
55
|
-
"templates",
|
56
|
-
"#{template_symbol}.html.erb"
|
57
|
-
)
|
58
|
-
Pathname.new(template_path).cleanpath.to_s
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
attr_accessor :manifest
|
63
|
-
|
64
|
-
def initialize(manifest)
|
65
|
-
self.manifest = manifest
|
66
|
-
end
|
67
|
-
|
68
|
-
def render_html_list(data, skip_wrapper: false)
|
69
|
-
html = ""
|
70
|
-
|
71
|
-
case data
|
72
|
-
when ::Hash
|
73
|
-
html << "<ul>" unless skip_wrapper
|
74
|
-
data.each do |key, value|
|
75
|
-
html << "<li>#{key}"
|
76
|
-
html << "<ul>"
|
77
|
-
html << render_html_list(value, skip_wrapper: true)
|
78
|
-
html << "</ul>"
|
79
|
-
html << "</li>"
|
80
|
-
end
|
81
|
-
html << "</ul>" unless skip_wrapper
|
82
|
-
when ::Array
|
83
|
-
html << "<ul>" unless skip_wrapper
|
84
|
-
data.each do |item|
|
85
|
-
html << render_html_list(item)
|
86
|
-
end
|
87
|
-
html << "</ul>" unless skip_wrapper
|
88
|
-
when Manifest::Attributes
|
89
|
-
html << "<ul>" unless skip_wrapper
|
90
|
-
data.relevant_manifest.each_pair do |key, value|
|
91
|
-
if key.to_s == "type"
|
92
|
-
next
|
93
|
-
end
|
94
|
-
|
95
|
-
if key.to_s == "element_type_declarations"
|
96
|
-
key = :attributes
|
97
|
-
value = data.attribute_declarations
|
98
|
-
end
|
99
|
-
html << "<li>#{key}"
|
100
|
-
html << "<ul>"
|
101
|
-
html << render_html_list(value, skip_wrapper: true)
|
102
|
-
html << "</ul>"
|
103
|
-
html << "</li>"
|
104
|
-
end
|
105
|
-
html << "</ul>" unless skip_wrapper
|
106
|
-
when Manifest::Array
|
107
|
-
html << "<ul>" unless skip_wrapper
|
108
|
-
data.relevant_manifest.each_pair do |key, value|
|
109
|
-
next if key == :element_type_declaration
|
110
|
-
|
111
|
-
if key.to_s == "type"
|
112
|
-
value = root_manifest.lookup_path(key, value)
|
113
|
-
end
|
114
|
-
html << "<li>#{key}"
|
115
|
-
html << "<ul>"
|
116
|
-
html << render_html_list(value, skip_wrapper: true)
|
117
|
-
html << "</ul>"
|
118
|
-
html << "</li>"
|
119
|
-
end
|
120
|
-
html << render_html_list({ element_type: data.element_type }, skip_wrapper: true)
|
121
|
-
html << "</ul>" unless skip_wrapper
|
122
|
-
when Manifest::TypeDeclaration
|
123
|
-
html << "<ul>" unless skip_wrapper
|
124
|
-
data.relevant_manifest.each_pair do |key, value|
|
125
|
-
if key.to_s == "type"
|
126
|
-
value = root_manifest.lookup_path(key, value)
|
127
|
-
end
|
128
|
-
html << "<li>#{key}"
|
129
|
-
html << "<ul>"
|
130
|
-
html << render_html_list(value, skip_wrapper: true)
|
131
|
-
html << "</ul>"
|
132
|
-
html << "</li>"
|
133
|
-
end
|
134
|
-
html << "</ul>" unless skip_wrapper
|
135
|
-
when Manifest::Type, Manifest::Command, Manifest::Error
|
136
|
-
html << foobara_reference_link(data)
|
137
|
-
when Manifest::PossibleError
|
138
|
-
html << render_html_list(data.error)
|
139
|
-
else
|
140
|
-
html << "<li>#{data}</li>"
|
141
|
-
end
|
142
|
-
|
143
|
-
html
|
144
|
-
end
|
145
|
-
|
146
|
-
def foobara_reference_link(manifest)
|
147
|
-
path = "/help/#{manifest.reference}"
|
148
|
-
|
149
|
-
"<a href=\"#{path}\">#{manifest.reference.split("::").last}</a>"
|
150
|
-
end
|
151
|
-
|
152
|
-
def root_manifest
|
153
|
-
@root_manifest ||= Manifest::RootManifest.new(manifest.root_manifest)
|
154
|
-
end
|
155
|
-
|
156
|
-
def template_path
|
157
|
-
self.class.template_path
|
158
|
-
end
|
159
|
-
|
160
|
-
def method_missing(method_name, *, &)
|
161
|
-
if manifest.respond_to?(method_name)
|
162
|
-
manifest.send(method_name, *, &)
|
163
|
-
else
|
164
|
-
# :nocov:
|
165
|
-
super
|
166
|
-
# :nocov:
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def respond_to_missing?(method_name, include_private = false)
|
171
|
-
manifest.respond_to?(method_name, include_private)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= full_domain_name %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= full_error_name %>
|
data/projects/command_connectors_http/src/http/commands/help/templates/organization.html.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<%= full_organization_name %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= full_processor_name %>
|
data/projects/command_connectors_http/src/http/commands/help/templates/processor_class.html.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<%= full_processor_class_name %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= full_type_name %>
|
@@ -1,98 +0,0 @@
|
|
1
|
-
module Foobara
|
2
|
-
module CommandConnectors
|
3
|
-
class Http < CommandConnector
|
4
|
-
module Commands
|
5
|
-
class Help < Command
|
6
|
-
description "Will extract items from the request to help with. Assumes the help is desired in HTML format"
|
7
|
-
inputs request: Request
|
8
|
-
result :string
|
9
|
-
possible_error CommandConnector::NotFoundError
|
10
|
-
|
11
|
-
def execute
|
12
|
-
load_manifest
|
13
|
-
determine_object_to_help_with
|
14
|
-
build_presenter
|
15
|
-
load_template
|
16
|
-
generate_html_from_template
|
17
|
-
set_header_to_html
|
18
|
-
|
19
|
-
html
|
20
|
-
end
|
21
|
-
|
22
|
-
attr_accessor :raw_manifest, :root_manifest, :object_to_help_with, :template, :html, :presenter
|
23
|
-
|
24
|
-
def load_manifest
|
25
|
-
self.raw_manifest = command_connector.foobara_manifest
|
26
|
-
self.root_manifest = Manifest::RootManifest.new(raw_manifest)
|
27
|
-
end
|
28
|
-
|
29
|
-
def determine_object_to_help_with(mode: Namespace::LookupMode::ABSOLUTE)
|
30
|
-
arg = request.argument
|
31
|
-
|
32
|
-
if arg
|
33
|
-
result = command_connector.command_registry.foobara_lookup(arg, mode:)
|
34
|
-
|
35
|
-
if result
|
36
|
-
self.object_to_help_with = result
|
37
|
-
else
|
38
|
-
result = GlobalOrganization.foobara_lookup(arg, mode:)
|
39
|
-
|
40
|
-
if result && root_manifest.contains?(result.foobara_manifest_reference,
|
41
|
-
result.scoped_category)
|
42
|
-
self.object_to_help_with = result
|
43
|
-
elsif mode == Namespace::LookupMode::ABSOLUTE
|
44
|
-
determine_object_to_help_with(mode: Namespace::LookupMode::GENERAL)
|
45
|
-
elsif mode == Namespace::LookupMode::GENERAL
|
46
|
-
determine_object_to_help_with(mode: Namespace::LookupMode::RELAXED)
|
47
|
-
else
|
48
|
-
# TODO: add an input error instead for missing record to trigger 404
|
49
|
-
add_runtime_error(CommandConnector::NotFoundError.new(arg))
|
50
|
-
end
|
51
|
-
end
|
52
|
-
else
|
53
|
-
self.object_to_help_with = root_manifest
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def build_presenter
|
58
|
-
self.presenter = Help::Presenter.for(manifest_to_help_with)
|
59
|
-
end
|
60
|
-
|
61
|
-
def template_path
|
62
|
-
presenter.template_path
|
63
|
-
end
|
64
|
-
|
65
|
-
def load_template
|
66
|
-
template_body = File.read(template_path)
|
67
|
-
|
68
|
-
erb = ERB.new(template_body)
|
69
|
-
erb.filename = template_path
|
70
|
-
|
71
|
-
self.template = erb
|
72
|
-
end
|
73
|
-
|
74
|
-
def generate_html_from_template
|
75
|
-
self.html = template.result(presenter.instance_eval { binding })
|
76
|
-
end
|
77
|
-
|
78
|
-
def set_header_to_html
|
79
|
-
request.response_headers ||= {}
|
80
|
-
request.response_headers = request.response_headers.merge("content-type" => "text/html")
|
81
|
-
end
|
82
|
-
|
83
|
-
def manifest_to_help_with
|
84
|
-
@manifest_to_help_with ||= if object_to_help_with.is_a?(Manifest::BaseManifest)
|
85
|
-
object_to_help_with
|
86
|
-
else
|
87
|
-
root_manifest.lookup(object_to_help_with.foobara_manifest_reference)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def command_connector
|
92
|
-
request.command_connector
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require "uri"
|
2
|
-
|
3
|
-
module Foobara
|
4
|
-
module CommandConnectors
|
5
|
-
class Http < CommandConnector
|
6
|
-
class Request < CommandConnectors::Request
|
7
|
-
attr_accessor :path,
|
8
|
-
:method,
|
9
|
-
:headers,
|
10
|
-
:query_string,
|
11
|
-
:body,
|
12
|
-
:scheme,
|
13
|
-
:host,
|
14
|
-
:port,
|
15
|
-
:cookies,
|
16
|
-
:remote_ip,
|
17
|
-
:response_headers
|
18
|
-
|
19
|
-
def initialize(
|
20
|
-
path:,
|
21
|
-
method: nil,
|
22
|
-
headers: {},
|
23
|
-
query_string: "",
|
24
|
-
body: "",
|
25
|
-
scheme: nil,
|
26
|
-
host: nil,
|
27
|
-
port: nil,
|
28
|
-
cookies: nil,
|
29
|
-
remote_ip: nil
|
30
|
-
)
|
31
|
-
self.path = path
|
32
|
-
self.method = method
|
33
|
-
self.headers = headers
|
34
|
-
self.query_string = query_string
|
35
|
-
self.body = body
|
36
|
-
self.scheme = scheme
|
37
|
-
self.host = host
|
38
|
-
self.port = port
|
39
|
-
self.cookies = cookies
|
40
|
-
self.remote_ip = remote_ip
|
41
|
-
|
42
|
-
super()
|
43
|
-
end
|
44
|
-
|
45
|
-
def url
|
46
|
-
URI::Generic.build(
|
47
|
-
scheme:,
|
48
|
-
host:,
|
49
|
-
port:,
|
50
|
-
path:,
|
51
|
-
query: query_string.nil? || query_string.empty? ? nil : query_string
|
52
|
-
).to_s
|
53
|
-
end
|
54
|
-
|
55
|
-
def inputs
|
56
|
-
@inputs ||= parsed_body.merge(parsed_query_string)
|
57
|
-
end
|
58
|
-
|
59
|
-
def full_command_name
|
60
|
-
unless defined?(@full_command_name)
|
61
|
-
set_action_and_command_name
|
62
|
-
end
|
63
|
-
|
64
|
-
@full_command_name
|
65
|
-
end
|
66
|
-
|
67
|
-
def parsed_body
|
68
|
-
body.empty? ? {} : JSON.parse(body)
|
69
|
-
end
|
70
|
-
|
71
|
-
def parsed_query_string
|
72
|
-
if query_string.nil? || query_string.empty?
|
73
|
-
{}
|
74
|
-
else
|
75
|
-
# TODO: override this in rack connector to use better rack utils
|
76
|
-
CGI.parse(query_string).transform_values!(&:first)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def action
|
81
|
-
unless defined?(@action)
|
82
|
-
set_action_and_command_name
|
83
|
-
end
|
84
|
-
|
85
|
-
@action
|
86
|
-
end
|
87
|
-
|
88
|
-
def argument
|
89
|
-
path.split("/")[2]
|
90
|
-
end
|
91
|
-
|
92
|
-
def set_action_and_command_name
|
93
|
-
@action, @full_command_name = path[1..].split("/")
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|