Class: Smooth::Response
Direct Known Subclasses
Instance Attribute Summary collapse
-
#command_action ⇒ Object
Returns the value of attribute command_action.
-
#current_user ⇒ Object
Returns the value of attribute current_user.
-
#event_namespace ⇒ Object
Returns the value of attribute event_namespace.
-
#object ⇒ Object
Returns the value of attribute object.
-
#outcome ⇒ Object
readonly
Returns the value of attribute outcome.
-
#request_headers ⇒ Object
Returns the value of attribute request_headers.
-
#serializer ⇒ Object
Returns the value of attribute serializer.
-
#serializer_klass ⇒ Object
Returns the value of attribute serializer_klass.
-
#serializer_options ⇒ Object
readonly
Returns the value of attribute serializer_options.
-
#success ⇒ Object
Returns the value of attribute success.
Instance Method Summary collapse
- #body ⇒ Object
- #headers ⇒ Object
-
#initialize(outcome, serializer_options = {}) ⇒ Response
constructor
A new instance of Response.
- #options ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
- #to_rack ⇒ Object
Constructor Details
#initialize(outcome, serializer_options = {}) ⇒ Response
Returns a new instance of Response.
7 8 9 10 |
# File 'lib/smooth/response.rb', line 7 def initialize(outcome, = {}) @outcome = outcome = end |
Instance Attribute Details
#command_action ⇒ Object
Returns the value of attribute command_action.
5 6 7 |
# File 'lib/smooth/response.rb', line 5 def command_action @command_action end |
#current_user ⇒ Object
Returns the value of attribute current_user.
5 6 7 |
# File 'lib/smooth/response.rb', line 5 def current_user @current_user end |
#event_namespace ⇒ Object
Returns the value of attribute event_namespace.
5 6 7 |
# File 'lib/smooth/response.rb', line 5 def event_namespace @event_namespace end |
#object ⇒ Object
Returns the value of attribute object.
5 6 7 |
# File 'lib/smooth/response.rb', line 5 def object @object end |
#outcome ⇒ Object (readonly)
Returns the value of attribute outcome.
3 4 5 |
# File 'lib/smooth/response.rb', line 3 def outcome @outcome end |
#request_headers ⇒ Object
Returns the value of attribute request_headers.
5 6 7 |
# File 'lib/smooth/response.rb', line 5 def request_headers @request_headers end |
#serializer ⇒ Object
Returns the value of attribute serializer.
5 6 7 |
# File 'lib/smooth/response.rb', line 5 def serializer @serializer end |
#serializer_klass ⇒ Object
Returns the value of attribute serializer_klass.
5 6 7 |
# File 'lib/smooth/response.rb', line 5 def serializer_klass @serializer_klass end |
#serializer_options ⇒ Object (readonly)
Returns the value of attribute serializer_options.
3 4 5 |
# File 'lib/smooth/response.rb', line 3 def end |
#success ⇒ Object
Returns the value of attribute success.
5 6 7 |
# File 'lib/smooth/response.rb', line 5 def success @success end |
Instance Method Details
#body ⇒ Object
30 31 32 |
# File 'lib/smooth/response.rb', line 30 def body serializer.new(object, ).to_json() end |
#headers ⇒ Object
16 17 18 19 20 |
# File 'lib/smooth/response.rb', line 16 def headers { 'Content-Type' => 'application/json' } end |
#options ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/smooth/response.rb', line 22 def if success? && serializer ( || {}).merge(serializer: serializer, scope: current_user) else .merge(scope: current_user) end end |
#status ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/smooth/response.rb', line 48 def status case when success? 200 else 400 end end |
#success? ⇒ Boolean
44 45 46 |
# File 'lib/smooth/response.rb', line 44 def success? @success || (outcome && outcome.success?) end |
#to_rack ⇒ Object
12 13 14 |
# File 'lib/smooth/response.rb', line 12 def to_rack [status, headers, [body]] end |