Class: Vx::Common::AMQP::Formatter
- Inherits:
-
Object
- Object
- Vx::Common::AMQP::Formatter
- Defined in:
- lib/vx/common/amqp/formatter.rb
Defined Under Namespace
Classes: Format
Constant Summary collapse
- @@formats =
{}
Class Method Summary collapse
- .define(content_type, &block) ⇒ Object
- .formats ⇒ Object
- .lookup(content_type) ⇒ Object
- .pack(content_type, body) ⇒ Object
- .unpack(content_type, model, body) ⇒ Object
Class Method Details
.define(content_type, &block) ⇒ Object
38 39 40 41 42 |
# File 'lib/vx/common/amqp/formatter.rb', line 38 def define(content_type, &block) fmt = Format.new content_type fmt.instance_eval(&block) formats.merge! content_type => fmt end |
.formats ⇒ Object
34 35 36 |
# File 'lib/vx/common/amqp/formatter.rb', line 34 def formats @@formats end |
.lookup(content_type) ⇒ Object
44 45 46 |
# File 'lib/vx/common/amqp/formatter.rb', line 44 def lookup(content_type) formats[content_type] end |
.pack(content_type, body) ⇒ Object
48 49 50 51 52 |
# File 'lib/vx/common/amqp/formatter.rb', line 48 def pack(content_type, body) if fmt = lookup(content_type) fmt.pack.call(body) end end |
.unpack(content_type, model, body) ⇒ Object
54 55 56 57 58 |
# File 'lib/vx/common/amqp/formatter.rb', line 54 def unpack(content_type, model, body) if fmt = lookup(content_type) fmt.unpack.call(body, model) end end |