lib/pragma/operation/base.rb in pragma-operation-1.0.0 vs lib/pragma/operation/base.rb in pragma-operation-1.1.0
- old
+ new
@@ -112,31 +112,30 @@
context.params
end
# Sets the status and resource to respond with.
#
- # You can achieve the same result by setting +context.status+ and +context.resource+ wherever
- # you want in {#call}.
+ # You can achieve the same result by setting +context.status+, +context.headers+ and
+ # +context.resource+ wherever you want in {#call}.
#
# Note that calling this method doesn't halt the execution of the operation and that this
# method can be called multiple times, overriding the previous context.
#
# @param status [Integer|Symbol] an HTTP status code
+ # @param headers [Hash] HTTP headers
# @param resource [Object] an object responding to +#to_json+
- def respond_with(status:, resource:)
+ def respond_with(status: :ok, headers: {}, resource:)
context.status = status
+ context.headers = headers.to_h
context.resource = resource
end
# Same as {#respond_with}, but also halts the execution of the operation.
#
- # @param status [Integer|Symbol] an HTTP status code
- # @param resource [Object] an object responding to +#to_json+
- #
# @see #respond_with
- def respond_with!(status:, resource:)
- respond_with status: status, resource: resource
+ def respond_with!(*args)
+ respond_with *args
fail Halt
end
# Sets the status to respond with.
#
@@ -185,9 +184,10 @@
end
end
def setup_context
context.params ||= {}
+ context.headers = {}
end
def handle_halt(interactor)
interactor.call
rescue Halt # rubocop:disable Lint/HandleExceptions