lib/azeroth/request_handler.rb in azeroth-0.8.0 vs lib/azeroth/request_handler.rb in azeroth-0.8.1
- old
+ new
@@ -17,11 +17,11 @@
autoload :Update, 'azeroth/request_handler/update'
# @param controller [ApplicationController]
# @param model [Azeroth::Model]
def initialize(controller, model, options)
- @controller = controller
+ @controller = ControllerInterface.new(controller)
@model = model
@options = options
end
# process the request
@@ -33,16 +33,15 @@
#
# @return [String]
def process
return unless json?
- json = model.decorate(resource)
- response_status = status
-
- controller.instance_eval do
- render(json: json, status: response_status)
- end
+ controller.add_headers(headers)
+ controller.render_json(
+ model.decorate(resource),
+ status
+ )
end
private
attr_reader :controller, :model, :options
@@ -138,8 +137,18 @@
# Collection scope of the resource
#
# @return [ActiveRecord::Relation]
def collection
@collection = controller.send(model.plural)
+ end
+
+ # @private
+ # @abstract
+ #
+ # Headers to be added
+ #
+ # @return [Hash]
+ def headers
+ {}
end
end
end