@@ 112-126 (lines=15) @@ | ||
109 | # @param [Object] source |
|
110 | # @param [AMA::Entity::Mapper::Type::Attribute] attribute |
|
111 | # @param [AMA::Entity::Mapper::Context] context |
|
112 | def map_attribute(source, attribute, context) |
|
113 | message = "Extracting attribute #{attribute.to_def} " \ |
|
114 | "from #{source.class}" |
|
115 | context.logger.debug(message) |
|
116 | successful(attribute.types, Mapper::Error) do |type| |
|
117 | if source.nil? && attribute.nullable |
|
118 | context.logger.debug('Found legal nil, short-circuiting') |
|
119 | break nil |
|
120 | end |
|
121 | result = map_type(source, type, context) |
|
122 | context.logger.debug("Validating resulting #{attribute.to_def}") |
|
123 | attribute.valid!(result, context) |
|
124 | result |
|
125 | end |
|
126 | end |
|
127 | ||
128 | # @param [Object] target |
|
129 | # @param [AMA::Entity::Mapper::Type] type |
|
@@ 59-69 (lines=11) @@ | ||
56 | # @param [Object] source |
|
57 | # @param [Array<AMA::Entity::Mapper::Type] types |
|
58 | # @param [AMA::Entity::Mapper::Context] context |
|
59 | def map_unsafe(source, types, context) |
|
60 | message = "Mapping #{source.class} into one of: " \ |
|
61 | "#{types.map(&:to_def).join(', ')}" |
|
62 | context.logger.debug(message) |
|
63 | successful(types, Mapper::Error, context) do |type| |
|
64 | result = map_type(source, type, context) |
|
65 | context.logger.debug("Validating resulting #{type.to_def}") |
|
66 | type.valid!(result, context) |
|
67 | result |
|
68 | end |
|
69 | end |
|
70 | ||
71 | # @param [Object] source |
|
72 | # @param [AMA::Entity::Mapper::Type] type |