Total Complexity | 4 |
Total Lines | 28 |
Duplicated Lines | 100 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | # frozen_string_literal: true |
||
14 | class Enumerator < API::Enumerator |
||
15 | include Mixin::Errors |
||
16 | |||
17 | # @param [AMA::Entity::Mapper::API::Enumerator] processor |
||
18 | def initialize(processor) |
||
19 | @processor = processor |
||
20 | @fallback = Default::Enumerator::INSTANCE |
||
21 | end |
||
22 | |||
23 | # @param [Object] entity |
||
24 | # @param [AMA::Entity::Mapper::Type] type |
||
25 | # @param [AMA::Entity::Mapper::Context] context |
||
26 | def enumerate(entity, type, context = nil) |
||
27 | context ||= Context.new |
||
28 | @processor.enumerate(entity, type, context) do |e, t, c| |
||
29 | @fallback.enumerate(e, t, c) |
||
30 | end |
||
31 | rescue StandardError => e |
||
32 | raise_if_internal(e) |
||
33 | message = "Error while enumerating #{entity.class} " \ |
||
34 | "(type: #{type}) attributes using #{@processor}" |
||
35 | if e.is_a?(ArgumentError) |
||
36 | message += "Does #{@processor}#enumerate have signature " \ |
||
37 | '(entity, type, context = nil)?' |
||
38 | end |
||
39 | mapping_error(message, parent: e, context: context) |
||
40 | end |
||
41 | end |
||
42 | end |
||
47 |