Module: Xio::Serializer

Extended by:
Serializer
Included in:
HTTP, Resource, Serializer
Defined in:
lib/xio/serializer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
# File 'lib/xio/serializer.rb', line 6

def self.included(klass)
  klass.extend(self)
end

Instance Method Details

#decode(content) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xio/serializer.rb', line 22

def decode(content)
  if content.is_a?(String)
    if MultiJson.respond_to?(:dump)
      MultiJson.load(content)
    else
      MultiJson.decode(content)
    end
  else
    content
  end
end

#encode(content) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/xio/serializer.rb', line 10

def encode(content)
  if content.is_a?(String) || content.nil?
    content
  else
    if MultiJson.respond_to?(:dump)
      MultiJson.dump(content)
    else
      MultiJson.encode(content)
    end
  end
end