| Total Complexity | 3 |
| Total Lines | 18 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # frozen_string_literal: true |
||
| 12 | class Factory < API::Factory |
||
| 13 | include Mixin::Errors |
||
| 14 | |||
| 15 | INSTANCE = new |
||
| 16 | |||
| 17 | # @param [AMA::Entity::Mapper::Type] type |
||
| 18 | # @param [Object] _data |
||
| 19 | # @param [AMA::Entity::Mapper::Context] context |
||
| 20 | def create(type, _data = nil, context = nil) |
||
| 21 | type.type.new |
||
| 22 | rescue StandardError => e |
||
| 23 | message = "Failed to instantiate #{type} directly from class" |
||
| 24 | if e.is_a?(ArgumentError) |
||
| 25 | message += '. Does it have parameterless #initialize() method?' |
||
| 26 | end |
||
| 27 | mapping_error(message, parent: e, context: context) |
||
| 28 | end |
||
| 29 | end |
||
| 30 | end |
||
| 35 |