Class: SavonHelper::TypeMapping
- Defined in:
- lib/savon_helper/type_mappings.rb
Overview
A TypeMapping class is responsible for converting between Savon primitive types and Ruby Types
Direct Known Subclasses
ArrayMapping, BooleanMapping, DatetimeMapping, EnumMapping, FloatMapping, HintMapping, IntegerMapping, MissingMapping, StringMapping
Converting collapse
- #to_native(data) ⇒ Object abstract
- #to_savon(value) ⇒ Object abstract
Instance Method Summary collapse
- #default_value ⇒ Object abstract
-
#description ⇒ String
Return the description.
-
#initialize(name = '', description = '') ⇒ TypeMapping
constructor
A new instance of TypeMapping with description.
- #object_klass ⇒ Class abstract
- #type_string ⇒ String abstract
-
#warn_unparseable_data(data, interface) ⇒ Object
Warn about unparsable mapping.
Constructor Details
#initialize(name = '', description = '') ⇒ TypeMapping
A new instance of TypeMapping with description
11 12 13 14 |
# File 'lib/savon_helper/type_mappings.rb', line 11 def initialize(name='', description='') @name = name @description = description end |
Instance Method Details
#default_value ⇒ Object
This method is abstract.
Return the default value the mapping.
54 55 56 |
# File 'lib/savon_helper/type_mappings.rb', line 54 def default_value raise "#{self.class}##{__method__}() not implemented!" end |
#description ⇒ String
Return the description
36 37 38 |
# File 'lib/savon_helper/type_mappings.rb', line 36 def description @description end |
#object_klass ⇒ Class
This method is abstract.
Return the class represented by the mapping.
42 43 44 |
# File 'lib/savon_helper/type_mappings.rb', line 42 def object_klass raise "#{self.class}##{__method__}() not implemented!" end |
#to_native(data) ⇒ Object
This method is abstract.
Convert from Savon data to Ruby value
21 22 23 |
# File 'lib/savon_helper/type_mappings.rb', line 21 def to_native(data) raise "#{self.class}##{__method__}(#{data.inspect}) not implemented!" end |
#to_savon(value) ⇒ Object
This method is abstract.
Convert from Ruby value type to Savon data
28 29 30 |
# File 'lib/savon_helper/type_mappings.rb', line 28 def to_savon(value) raise "#{self.class}##{__method__}(#{value.inspect}) not implemented!" end |
#type_string ⇒ String
This method is abstract.
Return the class description represented by the mapping.
48 49 50 |
# File 'lib/savon_helper/type_mappings.rb', line 48 def type_string raise "#{self.class}##{__method__}() not implemented!" end |
#warn_unparseable_data(data, interface) ⇒ Object
TODO:
Check if mappings can be derived from klass
Warn about unparsable mapping
61 62 63 64 65 |
# File 'lib/savon_helper/type_mappings.rb', line 61 def warn_unparseable_data(data, interface) = "Can't parse #{type_string} #{@name.inspect}: #{data.inspect}" interface.logger.warn() self.default_value() end |