Class: Vx::Lib::Consumer::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/vx/lib/consumer/serializer.rb

Defined Under Namespace

Classes: Type

Constant Summary collapse

@@types =
{}

Class Method Summary collapse

Class Method Details

.define(content_type, &block) ⇒ Object



24
25
26
27
28
# File 'lib/vx/lib/consumer/serializer.rb', line 24

def define(content_type, &block)
  fmt = Type.new content_type
  fmt.instance_eval(&block)
  types.merge! content_type => fmt
end

.lookup(content_type) ⇒ Object



30
31
32
# File 'lib/vx/lib/consumer/serializer.rb', line 30

def lookup(content_type)
  types[content_type]
end

.pack(content_type, body) ⇒ Object



34
35
36
37
38
# File 'lib/vx/lib/consumer/serializer.rb', line 34

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

.typesObject



20
21
22
# File 'lib/vx/lib/consumer/serializer.rb', line 20

def types
  @@types
end

.unpack(content_type, body, model) ⇒ Object



40
41
42
43
44
# File 'lib/vx/lib/consumer/serializer.rb', line 40

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