Class: Leadlight::TypeMap::DefaultType

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

Instance Method Summary collapse

Constructor Details

#initialize(codec) ⇒ DefaultType

Returns a new instance of DefaultType.



80
81
82
# File 'lib/leadlight/type_map.rb', line 80

def initialize(codec)
  @codec = codec
end

Instance Method Details

#decode(content_type, entity_body, options = {}) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/leadlight/type_map.rb', line 91

def decode(content_type, entity_body, options={})
  case entity_body.to_s.size
  when 0,1 # No valid JSON document is smaller than 2 bytes
    Blank.new
  else
    @codec.decode(content_type, entity_body, options)
  end
end

#encode(object, options = {}) ⇒ Object



84
85
86
87
88
89
# File 'lib/leadlight/type_map.rb', line 84

def encode(object, options={})
  return Entity.new(nil, nil) if object.nil?
  content_type = options.delete(:content_type){"application/json"}
  body = @codec.encode(content_type, object, options)
  Entity.new(content_type, body)
end