Class: Hx::Interop::ContentTypes

Inherits:
Hash
  • Object
show all
Defined in:
lib/interop/content_types.rb

Overview

A collection of marshalers, with content-type strings, for decoding messages by content type.

Instance Method Summary collapse

Instance Method Details

#<<(content_type) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/interop/content_types.rb', line 11

def <<(content_type)
  content_type.is_a? ContentType or
    raise ArgumentError, "Expected an instance of #{ContentType}"
  key? content_type.name and
    raise ArgumentError, "Content type #{content_type.name} is already registered"
  self[content_type.name] = content_type
  self
end

#decode(message) ⇒ Object



20
21
22
# File 'lib/interop/content_types.rb', line 20

def decode(message)
  delegate message[Headers::CONTENT_TYPE], :decode, message
end

#dump(content_type, obj) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/interop/content_types.rb', line 28

i[load dump encode encode_to].each do |name|
  class_eval "    def \#{name}(content_type, *args)          # def load(content_type, *args)\n      delegate content_type, :\#{name}, *args  #   delegate content_type, :load, *args\n    end                                       # end\n  RUBY\nend\n", __FILE__, __LINE__ + 1

#encode(content_type, obj) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/interop/content_types.rb', line 28

i[load dump encode encode_to].each do |name|
  class_eval "    def \#{name}(content_type, *args)          # def load(content_type, *args)\n      delegate content_type, :\#{name}, *args  #   delegate content_type, :load, *args\n    end                                       # end\n  RUBY\nend\n", __FILE__, __LINE__ + 1

#encode_to(content_type, obj, message) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/interop/content_types.rb', line 28

i[load dump encode encode_to].each do |name|
  class_eval "    def \#{name}(content_type, *args)          # def load(content_type, *args)\n      delegate content_type, :\#{name}, *args  #   delegate content_type, :load, *args\n    end                                       # end\n  RUBY\nend\n", __FILE__, __LINE__ + 1

#load(content_type, str) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/interop/content_types.rb', line 28

i[load dump encode encode_to].each do |name|
  class_eval "    def \#{name}(content_type, *args)          # def load(content_type, *args)\n      delegate content_type, :\#{name}, *args  #   delegate content_type, :load, *args\n    end                                       # end\n  RUBY\nend\n", __FILE__, __LINE__ + 1

#register(content_type, marshaler = nil) ⇒ Object



5
6
7
8
9
# File 'lib/interop/content_types.rb', line 5

def register(content_type, marshaler = nil)
  content_type = ContentType.new(content_type, marshaler) unless content_type.is_a? ContentType
  self << content_type
  content_type
end

#to_sObject



36
37
38
# File 'lib/interop/content_types.rb', line 36

def to_s
  keys.join ', '
end