Class: Leadlight::TypeMap::DefaultType
- Inherits:
-
Object
- Object
- Leadlight::TypeMap::DefaultType
- Defined in:
- lib/leadlight/type_map.rb
Instance Method Summary collapse
- #decode(content_type, entity_body, options = {}) ⇒ Object
- #encode(object, options = {}) ⇒ Object
-
#initialize(codec) ⇒ DefaultType
constructor
A new instance of DefaultType.
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, ={}) 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, ) end end |
#encode(object, options = {}) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/leadlight/type_map.rb', line 84 def encode(object, ={}) return Entity.new(nil, nil) if object.nil? content_type = .delete(:content_type){"application/json"} body = @codec.encode(content_type, object, ) Entity.new(content_type, body) end |