foobara-rails-command-connector 0.0.1 → 0.0.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/foobara/rails/controller.rb +38 -3
- data/lib/foobara/rails/routes.rb +3 -1
- data/src/rails_command_connector.rb +8 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85b87cf4ca9d03e7074214e48e8b360b8c4699413fa0e4afa3a8cc86308abd18
|
4
|
+
data.tar.gz: 35fd962b96178619a87d6fb9461e5a5b30f90985eb08efc020b94c89c789afcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04eca877f738fe6eb9ab755829752971d54a9065176723f8adb4ef2a0022fd6a80eeb4e346dbf05ad6d0154fa0393772eda5c3ad4d6b93350bc760fa62451e5e
|
7
|
+
data.tar.gz: 5e28e4449c228fcfe0bca3648e41e1c294c8b6851c564aaf3c35587b5e8ca6f315026d8d66d4d87d46ccd9d1940099153d331697894ad20d599650c13f82ff4e
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,47 @@
|
|
1
1
|
class Foobara::RailsController < ApplicationController
|
2
|
+
before_action :run_and_set_foobara_response
|
3
|
+
|
2
4
|
def run
|
3
|
-
|
4
|
-
|
5
|
+
end
|
6
|
+
|
7
|
+
def help
|
8
|
+
end
|
9
|
+
|
10
|
+
def list
|
11
|
+
end
|
12
|
+
|
13
|
+
def describe
|
14
|
+
end
|
15
|
+
|
16
|
+
def manifest
|
17
|
+
end
|
18
|
+
|
19
|
+
# TODO: add list and describe and manifest if it is different from describe
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def run_and_set_foobara_response
|
24
|
+
foobara_response = command_connector.run(self)
|
5
25
|
|
6
26
|
foobara_response.headers.each_pair do |key, value|
|
7
27
|
response.set_header(key, value)
|
8
28
|
end
|
9
29
|
|
10
|
-
|
30
|
+
format = if response.content_type == "application/json"
|
31
|
+
:json
|
32
|
+
else
|
33
|
+
:html
|
34
|
+
end
|
35
|
+
|
36
|
+
body = foobara_response.body
|
37
|
+
# rubocop:disable Rails/OutputSafety
|
38
|
+
body = body.html_safe if format == :html
|
39
|
+
# rubocop:enable Rails/OutputSafety
|
40
|
+
|
41
|
+
render format => body, status: foobara_response.status
|
42
|
+
end
|
43
|
+
|
44
|
+
def command_connector
|
45
|
+
Rails.application.config.foobara_command_connector
|
11
46
|
end
|
12
47
|
end
|
data/lib/foobara/rails/routes.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
ActionDispatch::Routing::Mapper.class_eval do
|
2
|
+
command_connector = Rails.application.config.foobara_command_connector
|
3
|
+
|
2
4
|
define_method :command do |*args, **opts, &block|
|
3
|
-
|
5
|
+
command_connector.connect(*args, **opts, &block)
|
4
6
|
end
|
5
7
|
end
|
@@ -7,22 +7,16 @@ module Foobara
|
|
7
7
|
class << self
|
8
8
|
# TODO: push this up the stack
|
9
9
|
def supported_actions
|
10
|
-
%i[run help describe list]
|
10
|
+
%i[run help describe list manifest]
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
attr_accessor :supported_actions
|
15
15
|
|
16
|
-
|
17
|
-
def initialize(*, supported_actions: self.class.supported_actions, **opts, &)
|
16
|
+
def initialize(*, supported_actions: self.class.supported_actions, **, &)
|
18
17
|
self.supported_actions = supported_actions
|
19
18
|
|
20
|
-
|
21
|
-
Foobara::CommandConnectors::Serializers::ErrorsSerializer,
|
22
|
-
Foobara::CommandConnectors::Serializers::JsonSerializer
|
23
|
-
]
|
24
|
-
|
25
|
-
super(*, **opts, &)
|
19
|
+
super(*, **, &)
|
26
20
|
|
27
21
|
install!
|
28
22
|
end
|
@@ -32,10 +26,15 @@ module Foobara
|
|
32
26
|
|
33
27
|
@installed = true
|
34
28
|
|
29
|
+
attach_to_rails_application_config!
|
35
30
|
install_controller!
|
36
31
|
install_routes!
|
37
32
|
end
|
38
33
|
|
34
|
+
def attach_to_rails_application_config!
|
35
|
+
Rails.application.config.foobara_command_connector = self
|
36
|
+
end
|
37
|
+
|
39
38
|
def install_routes!
|
40
39
|
prefix = self.prefix
|
41
40
|
connector = self
|