Class: JsonResponse
- Inherits:
-
Object
- Object
- JsonResponse
- Defined in:
- lib/json_response.rb
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #append(key, value) ⇒ Object
-
#initialize ⇒ JsonResponse
constructor
A new instance of JsonResponse.
- #negative ⇒ Object
- #positive ⇒ Object
- #serialize ⇒ Object
- #to_js(callback) ⇒ Object
Constructor Details
#initialize ⇒ JsonResponse
Returns a new instance of JsonResponse.
7 8 9 10 |
# File 'lib/json_response.rb', line 7 def initialize @status = false @data = {} end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/json_response.rb', line 5 def status @status end |
Instance Method Details
#append(key, value) ⇒ Object
28 29 30 |
# File 'lib/json_response.rb', line 28 def append(key, value) @data[key] = value end |
#negative ⇒ Object
24 25 26 |
# File 'lib/json_response.rb', line 24 def negative @status = false end |
#positive ⇒ Object
20 21 22 |
# File 'lib/json_response.rb', line 20 def positive @status = true end |
#serialize ⇒ Object
12 13 14 |
# File 'lib/json_response.rb', line 12 def serialize { :status => @status, :data => @data }.to_json end |
#to_js(callback) ⇒ Object
16 17 18 |
# File 'lib/json_response.rb', line 16 def to_js(callback) "#{callback}(#{serialize});" end |