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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ae1b8b6c048bb6b9cc3df06eba1df841ea1e4018e1bd5f0acace319d182711e
4
- data.tar.gz: fa3cae90047164951eb6454326aaeac430d5bab664b925eeb51116b4abf6a0c3
3
+ metadata.gz: 85b87cf4ca9d03e7074214e48e8b360b8c4699413fa0e4afa3a8cc86308abd18
4
+ data.tar.gz: 35fd962b96178619a87d6fb9461e5a5b30f90985eb08efc020b94c89c789afcc
5
5
  SHA512:
6
- metadata.gz: e98dd53e0329739405de462fd3c936f0dae649def7aaa13bd73ccc7ef70cde66f0b970ee2121692b780186c4860d582b808e554914d4199ea61db0235d648dd6
7
- data.tar.gz: 6775e505090ee716a53f93a9b9f819a0d1ddbaad48bf1a90a88bf98016c6eeda8846d5e99f87ffd5d8cf4c0c5ffe541de1a102a926eaa238650cda4289d4c7c3
6
+ metadata.gz: 04eca877f738fe6eb9ab755829752971d54a9065176723f8adb4ef2a0022fd6a80eeb4e346dbf05ad6d0154fa0393772eda5c3ad4d6b93350bc760fa62451e5e
7
+ data.tar.gz: 5e28e4449c228fcfe0bca3648e41e1c294c8b6851c564aaf3c35587b5e8ca6f315026d8d66d4d87d46ccd9d1940099153d331697894ad20d599650c13f82ff4e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.0.3] - 2024-12-02
2
+
3
+ - Eliminate HTTP_COMMAND_CONNECTOR
4
+ - Add help, list, describe, and manifest actions
5
+ - Inherit default serializers
6
+
1
7
  ## [0.0.1] - 2024-12-01
2
8
 
3
9
  - 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,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
- # TODO: push these default serializers up into the base class
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
- opts[:default_serializers] ||= [
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
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi