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 Normalizer < API::Normalizer |
||
15 | include Mixin::Errors |
||
16 | |||
17 | # @param [AMA::Entity::Mapper::API::Normalizer] processor |
||
18 | def initialize(processor) |
||
19 | @processor = processor |
||
20 | @fallback = Default::Normalizer::INSTANCE |
||
21 | end |
||
22 | |||
23 | # @param [Object] entity |
||
24 | # @param [AMA::Entity::Mapper::Type] type |
||
25 | # @param [AMA::Entity::Mapper::Context] context |
||
26 | def normalize(entity, type, context = nil) |
||
27 | ctx = context || Context.new |
||
28 | @processor.normalize(entity, type, ctx) do |e, t, c| |
||
29 | @fallback.normalize(e, t, c) |
||
30 | end |
||
31 | rescue StandardError => e |
||
32 | raise_if_internal(e) |
||
33 | message = "Error while normalizing #{entity} (type: #{type}) " \ |
||
34 | "using #{@processor}" |
||
35 | if e.is_a?(ArgumentError) |
||
36 | message += "Does #{@processor}#normalize have signature " \ |
||
37 | '(entity, type, context = nil)?' |
||
38 | end |
||
39 | mapping_error(message, parent: e, context: ctx) |
||
40 | end |
||
41 | end |
||
42 | end |
||
47 |