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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ae1b8b6c048bb6b9cc3df06eba1df841ea1e4018e1bd5f0acace319d182711e
4
- data.tar.gz: fa3cae90047164951eb6454326aaeac430d5bab664b925eeb51116b4abf6a0c3
3
+ metadata.gz: '0108d1dff86cd03d6db21fdece9f448c9feb462d5338a355f3b0d745e5a170bf'
4
+ data.tar.gz: 91ae69130f9ebd42413eb50aa536131e6e43054b711ab3a45949030714947b01
5
5
  SHA512:
6
- metadata.gz: e98dd53e0329739405de462fd3c936f0dae649def7aaa13bd73ccc7ef70cde66f0b970ee2121692b780186c4860d582b808e554914d4199ea61db0235d648dd6
7
- data.tar.gz: 6775e505090ee716a53f93a9b9f819a0d1ddbaad48bf1a90a88bf98016c6eeda8846d5e99f87ffd5d8cf4c0c5ffe541de1a102a926eaa238650cda4289d4c7c3
6
+ metadata.gz: d97af871abcc501d3e8da272b5f064f0d3aa005f2a5ca069bc46bd0b4f5943399b25a890bae55cb329a13e2907b99ed6e49131fe47588f20babb62b7a6a112a9
7
+ data.tar.gz: d2e7868672d8bbe6f6cc6ebda4b4112140e558bd7664a8afc94e89103180546dabc92f6b12d6f51025b9d40efad65a2fc483f3172f742309efae56b561adf4dd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [0.0.2] - 2024-12-02
2
+
3
+ - Eliminate HTTP_COMMAND_CONNECTOR
4
+ - Add help, list, describe, and manifest actions
5
+
1
6
  ## [0.0.1] - 2024-12-01
2
7
 
3
8
  - Initial release
@@ -1,12 +1,47 @@
1
1
  class Foobara::RailsController < ApplicationController
2
+ before_action :run_and_set_foobara_response
3
+
2
4
  def run
3
- foobara_response = RAILS_COMMAND_CONNECTOR.run(self)
4
- foobara_response.command
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
- render json: foobara_response.body, status: foobara_response.status
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
@@ -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
- RAILS_COMMAND_CONNECTOR.connect(*args, **opts, &block)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-rails-command-connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi