Module: HappyMapper::SupportedTypes
- Extended by:
- SupportedTypes
- Included in:
- SupportedTypes
- Defined in:
- lib/happymapper/supported_types.rb
Defined Under Namespace
Classes: CastWhenType, NilOrAlreadyConverted
Instance Method Summary collapse
-
#register(type_converter) ⇒ Object
Add a new converter to the list of supported types.
-
#register_type(type, &block) ⇒ Object
An additional shortcut registration method that assumes that you want to perform a conversion on a specific type.
-
#types ⇒ Object
All of the registerd supported types that can be parsed.
Instance Method Details
#register(type_converter) ⇒ Object
Add a new converter to the list of supported types. A converter is an object that adheres to the protocol which is defined with two methods #apply?(value,convert_to_type) and #apply(value).
33 34 35 |
# File 'lib/happymapper/supported_types.rb', line 33 def register(type_converter) types.push type_converter end |
#register_type(type, &block) ⇒ Object
An additional shortcut registration method that assumes that you want to perform a conversion on a specific type. A block is provided which is the operation to perform when #apply(value) has been called.
48 49 50 |
# File 'lib/happymapper/supported_types.rb', line 48 def register_type(type,&block) register CastWhenType.new(type,&block) end |
#types ⇒ Object
All of the registerd supported types that can be parsed.
All types defined here are set through #register.
10 11 12 |
# File 'lib/happymapper/supported_types.rb', line 10 def types @types ||= [] end |