Class: Amber::Switch::Content::Json
Constant Summary
FORM_DATA_CONTENT, JSON_CONTENT, TEXT_CONTENT
Instance Attribute Summary
#type
Instance Method Summary
collapse
#body, #body=, #data
Constructor Details
#initialize(data = {}) ⇒ Json
Returns a new instance of Json.
4
5
6
|
# File 'lib/amber/switch/content/json.rb', line 4
def initialize(data = {})
super Amber::Switch::Content::JSON_CONTENT, data
end
|
Instance Method Details
#data=(data) ⇒ Object
8
9
10
11
12
|
# File 'lib/amber/switch/content/json.rb', line 8
def data=(data)
if data.is_a? Hash
super
end
end
|
#deserialize(data) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/amber/switch/content/json.rb', line 23
def deserialize(data)
if data.is_a? String
begin
return JSON.parse data
rescue Exception => e
p e
end
end
{}
end
|
#serialize(data) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/amber/switch/content/json.rb', line 14
def serialize(data)
begin
return JSON.generate data
rescue Exception => e
p e
end
""
end
|