Class: JsonResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/json_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJsonResponse

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

#statusObject (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

#negativeObject



24
25
26
# File 'lib/json_response.rb', line 24

def negative
  @status = false
end

#positiveObject



20
21
22
# File 'lib/json_response.rb', line 20

def positive
  @status = true
end

#serializeObject



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