Class: Vx::Consumer::Serializer
- Inherits:
-
Object
- Object
- Vx::Consumer::Serializer
- Defined in:
- lib/vx/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
23 24 25 26 27 |
# File 'lib/vx/consumer/serializer.rb', line 23 def define(content_type, &block) fmt = Type.new content_type fmt.instance_eval(&block) types.merge! content_type => fmt end |
.lookup(content_type) ⇒ Object
29 30 31 |
# File 'lib/vx/consumer/serializer.rb', line 29 def lookup(content_type) types[content_type] end |
.pack(content_type, body) ⇒ Object
33 34 35 36 37 |
# File 'lib/vx/consumer/serializer.rb', line 33 def pack(content_type, body) if fmt = lookup(content_type) fmt.pack.call(body) end end |
.types ⇒ Object
19 20 21 |
# File 'lib/vx/consumer/serializer.rb', line 19 def types @@types end |
.unpack(content_type, body, model) ⇒ Object
39 40 41 42 43 |
# File 'lib/vx/consumer/serializer.rb', line 39 def unpack(content_type, body, model) if fmt = lookup(content_type) fmt.unpack.call(body, model) end end |