class Smooth::Response
Attributes
command_action[RW]
current_user[RW]
event_namespace[RW]
object[RW]
outcome[R]
request_headers[RW]
serializer[RW]
serializer_klass[RW]
serializer_options[R]
success[RW]
Public Class Methods
new(outcome, serializer_options = {})
click to toggle source
# File lib/smooth/response.rb, line 7 def initialize(outcome, serializer_options = {}) @outcome = outcome @serializer_options = serializer_options end
Public Instance Methods
body()
click to toggle source
# File lib/smooth/response.rb, line 30 def body serializer.new(object, options).to_json(options) end
headers()
click to toggle source
# File lib/smooth/response.rb, line 16 def headers { 'Content-Type' => 'application/json' } end
options()
click to toggle source
# File lib/smooth/response.rb, line 22 def options if success? && serializer (@serializer_options || {}).merge(serializer: serializer, scope: current_user) else @serializer_options.merge(scope: current_user) end end
status()
click to toggle source
# File lib/smooth/response.rb, line 48 def status case when success? 200 else 400 end end
success?()
click to toggle source
# File lib/smooth/response.rb, line 44 def success? @success || (outcome && outcome.success?) end
to_rack()
click to toggle source
# File lib/smooth/response.rb, line 12 def to_rack [status, headers, [body]] end