Class: Hotwire::Response::Json
- Defined in:
- lib/hotwire/response/json.rb
Overview
Specialization responsible for producing responses in JSON format.
Defined Under Namespace
Instance Attribute Summary
Attributes inherited from Base
Attributes inherited from Base
Instance Method Summary collapse
-
#body ⇒ Object
Returns the datasource in JSON format.
-
#initialize(request) ⇒ Json
constructor
A new instance of Json.
Methods inherited from Base
#add_column, #add_columns, #set_data
Methods inherited from Base
#add_error, #valid?, #validate
Constructor Details
#initialize(request) ⇒ Json
Returns a new instance of Json.
6 7 8 9 |
# File 'lib/hotwire/response/json.rb', line 6 def initialize(request) super(request) @responseHandler = "google.visualization.Query.setResponse" end |
Instance Method Details
#body ⇒ Object
Returns the datasource in JSON format. It supports the responseHandler
parameter. All the errors are returned with the invalid_request
key. Warnings are unsupported (yet).
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hotwire/response/json.rb', line 14 def body rsp = {} rsp[:version] = @version rsp[:reqId] = @request[:reqId] if @request[:reqId] if valid? rsp[:status] = "ok" rsp[:table] = datatable unless data.nil? else rsp[:status] = "error" rsp[:errors] = @errors end "#{@request[:responseHandler] || @responseHandler}(#{rsp.to_json})" end |