Class: Jsapi::Controller::Response
- Inherits:
-
Object
- Object
- Jsapi::Controller::Response
- Defined in:
- lib/jsapi/controller/response.rb
Overview
Used to serialize a response.
Instance Method Summary collapse
-
#initialize(object, response, definitions) ⇒ Response
constructor
Creates a new instance to serialize
object
according toresponse
. -
#inspect ⇒ Object
:nodoc:.
-
#to_json ⇒ Object
Returns the JSON representation of the response as a
String
.
Constructor Details
#initialize(object, response, definitions) ⇒ Response
Creates a new instance to serialize object
according to response
. References are resolved to API components in definitions
.
10 11 12 13 14 |
# File 'lib/jsapi/controller/response.rb', line 10 def initialize(object, response, definitions) @object = object @response = response @definitions = definitions end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
16 17 18 |
# File 'lib/jsapi/controller/response.rb', line 16 def inspect # :nodoc: "#<#{self.class.name} #{@object.inspect}>" end |
#to_json ⇒ Object
Returns the JSON representation of the response as a String
.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/jsapi/controller/response.rb', line 21 def to_json(*) schema = @response.schema.resolve(@definitions) if @response.locale I18n.with_locale(@response.locale) do serialize(@object, schema) end else serialize(@object, schema) end.to_json end |