lib/foobara/rails/controller.rb in foobara-rails-command-connector-0.0.1 vs lib/foobara/rails/controller.rb in foobara-rails-command-connector-0.0.2
- old
+ new
@@ -1,12 +1,47 @@
class Foobara::RailsController < ApplicationController
+ before_action :run_and_set_foobara_response
+
def run
- foobara_response = RAILS_COMMAND_CONNECTOR.run(self)
- foobara_response.command
+ end
+ def help
+ end
+
+ def list
+ end
+
+ def describe
+ end
+
+ def manifest
+ end
+
+ # TODO: add list and describe and manifest if it is different from describe
+
+ private
+
+ def run_and_set_foobara_response
+ foobara_response = command_connector.run(self)
+
foobara_response.headers.each_pair do |key, value|
response.set_header(key, value)
end
- render json: foobara_response.body, status: foobara_response.status
+ format = if response.content_type == "application/json"
+ :json
+ else
+ :html
+ end
+
+ body = foobara_response.body
+ # rubocop:disable Rails/OutputSafety
+ body = body.html_safe if format == :html
+ # rubocop:enable Rails/OutputSafety
+
+ render format => body, status: foobara_response.status
+ end
+
+ def command_connector
+ Rails.application.config.foobara_command_connector
end
end