Class: Hx::Interop::ContentTypes
- Inherits:
-
Hash
- Object
- Hash
- Hx::Interop::ContentTypes
- 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
- #<<(content_type) ⇒ Object
- #decode(message) ⇒ Object
- #dump(content_type, obj) ⇒ Object
- #encode(content_type, obj) ⇒ Object
- #encode_to(content_type, obj, message) ⇒ Object
- #load(content_type, str) ⇒ Object
- #register(content_type, marshaler = nil) ⇒ Object
- #to_s ⇒ Object
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() delegate [Headers::CONTENT_TYPE], :decode, 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_s ⇒ Object
36 37 38 |
# File 'lib/interop/content_types.rb', line 36 def to_s keys.join ', ' end |