Class: Amber::Switch::Content::Json

Inherits:
Amber::Switch::Content show all
Includes:
Amber::Switch::ContentDelegate
Defined in:
lib/amber/switch/content/json.rb

Constant Summary

Constants inherited from Amber::Switch::Content

FORM_DATA_CONTENT, JSON_CONTENT, TEXT_CONTENT

Instance Attribute Summary

Attributes inherited from Amber::Switch::Content

#type

Instance Method Summary collapse

Methods inherited from Amber::Switch::Content

#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