foobara-rails-command-connector 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/foobara/rails/controller.rb +38 -3
- data/lib/foobara/rails/routes.rb +3 -1
- data/src/rails_command_connector.rb +6 -1
- 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: '0108d1dff86cd03d6db21fdece9f448c9feb462d5338a355f3b0d745e5a170bf'
|
4
|
+
data.tar.gz: 91ae69130f9ebd42413eb50aa536131e6e43054b711ab3a45949030714947b01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d97af871abcc501d3e8da272b5f064f0d3aa005f2a5ca069bc46bd0b4f5943399b25a890bae55cb329a13e2907b99ed6e49131fe47588f20babb62b7a6a112a9
|
7
|
+
data.tar.gz: d2e7868672d8bbe6f6cc6ebda4b4112140e558bd7664a8afc94e89103180546dabc92f6b12d6f51025b9d40efad65a2fc483f3172f742309efae56b561adf4dd
|
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,7 +7,7 @@ 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
|
|
@@ -32,10 +32,15 @@ module Foobara
|
|
32
32
|
|
33
33
|
@installed = true
|
34
34
|
|
35
|
+
attach_to_rails_application_config!
|
35
36
|
install_controller!
|
36
37
|
install_routes!
|
37
38
|
end
|
38
39
|
|
40
|
+
def attach_to_rails_application_config!
|
41
|
+
Rails.application.config.foobara_command_connector = self
|
42
|
+
end
|
43
|
+
|
39
44
|
def install_routes!
|
40
45
|
prefix = self.prefix
|
41
46
|
connector = self
|