Class: Evrone::Common::AMQP::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/evrone/common/amqp/formatter.rb

Defined Under Namespace

Classes: Format

Constant Summary collapse

@@formats =
{}

Class Method Summary collapse

Class Method Details

.define(content_type, &block) ⇒ Object



38
39
40
41
42
# File 'lib/evrone/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

.formatsObject



34
35
36
# File 'lib/evrone/common/amqp/formatter.rb', line 34

def formats
  @@formats
end

.lookup(content_type) ⇒ Object



44
45
46
# File 'lib/evrone/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/evrone/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/evrone/common/amqp/formatter.rb', line 54

def unpack(content_type, model, body)
  if fmt = lookup(content_type)
    fmt.unpack.call(body, model)
  end
end