Class: Vx::Lib::Consumer::Serializer
- Inherits:
-
Object
- Object
- Vx::Lib::Consumer::Serializer
- Defined in:
- lib/vx/lib/consumer/serializer.rb
Defined Under Namespace
Classes: Type
Constant Summary collapse
- @@types =
{}
Class Method Summary collapse
- .define(content_type, &block) ⇒ Object
- .lookup(content_type) ⇒ Object
- .pack(content_type, body) ⇒ Object
- .types ⇒ Object
- .unpack(content_type, body, model) ⇒ Object
Class Method Details
.define(content_type, &block) ⇒ Object
26 27 28 29 30 |
# File 'lib/vx/lib/consumer/serializer.rb', line 26 def define(content_type, &block) fmt = Type.new content_type fmt.instance_eval(&block) types.merge! content_type => fmt end |
.lookup(content_type) ⇒ Object
32 33 34 |
# File 'lib/vx/lib/consumer/serializer.rb', line 32 def lookup(content_type) types[content_type] end |
.pack(content_type, body) ⇒ Object
36 37 38 39 40 |
# File 'lib/vx/lib/consumer/serializer.rb', line 36 def pack(content_type, body) if fmt = lookup(content_type) fmt.pack.call(body) end end |
.types ⇒ Object
22 23 24 |
# File 'lib/vx/lib/consumer/serializer.rb', line 22 def types @@types end |
.unpack(content_type, body, model) ⇒ Object
42 43 44 45 46 |
# File 'lib/vx/lib/consumer/serializer.rb', line 42 def unpack(content_type, body, model) if fmt = lookup(content_type) fmt.unpack.call(body, model) end end |