| Total Complexity | 7 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | # frozen_string_literal: true |
||
| 12 | class Object |
||
| 13 | include ::AMA::Entity::Mapper::Mixin::Reflection |
||
| 14 | include ::AMA::Entity::Mapper::Mixin::Errors |
||
| 15 | |||
| 16 | def supports(*) |
||
| 17 | true |
||
| 18 | end |
||
| 19 | |||
| 20 | # @param [Object] source |
||
| 21 | # @param [AMA::Entity::Mapper::Engine::Context] context |
||
| 22 | # @param [AMA::Entity::Mapper::Type::Concrete] target_type |
||
| 23 | def denormalize(source, context, target_type) |
||
| 24 | return source if source.is_a?(target_type.type) |
||
| 25 | handler = compute_handler(target_type, context) |
||
| 26 | return target_type.type.send(handler, source, context) if handler |
||
| 27 | entity = target_type.factory.create(context, source) |
||
| 28 | extractor = target_type.extractor(source) |
||
| 29 | acceptor = target_type.acceptor(entity, context) |
||
| 30 | extractor.each do |attribute, value, segment = nil| |
||
| 31 | acceptor.accept(attribute, value, segment) |
||
| 32 | end |
||
| 33 | entity |
||
| 34 | end |
||
| 35 | |||
| 36 | private |
||
| 37 | |||
| 38 | def compute_handler(target_type, context) |
||
| 39 | handler = context.denormalization_method |
||
| 40 | handler && target_type.type.respond_to?(handler) ? handler : nil |
||
| 41 | end |
||
| 42 | end |
||
| 43 | end |
||
| 48 |