Class: Representors::SerializationFactoryBase
- Inherits:
-
Object
- Object
- Representors::SerializationFactoryBase
show all
- Defined in:
- lib/representors/serialization/serialization_factory_base.rb
Overview
Base class for factories that manages the registration of serialization classes and the common factory interface.
Class Method Summary
collapse
Class Method Details
.build(media_type, object) ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/representors/serialization/serialization_factory_base.rb', line 7
def self.build(media_type, object)
klass = serialization_class(media_type)
if klass
klass.new(object)
else
raise UnknownMediaTypeError, "Unknown media-type: #{media_type}."
end
end
|
16
17
18
19
20
|
# File 'lib/representors/serialization/serialization_factory_base.rb', line 16
def self.media_symbol_mapping
@media_symbol_mapping ||= registered_serialization_classes.map do |serialization_class|
serialization_class.media_symbols.map { |media_symbol| { media_symbol => serialization_class } }.reduce(:merge)
end.reduce(:merge)
end
|
22
23
24
25
26
|
# File 'lib/representors/serialization/serialization_factory_base.rb', line 22
def self.media_type_mapping
@media_type_mapping ||= registered_serialization_classes.map do |serializer|
serializer.media_types.map { |media_type| { media_type => serializer.media_symbols.first } }.reduce(:merge)
end.reduce(:merge)
end
|