Total Complexity | 6 |
Total Lines | 52 |
Duplicated Lines | 7.69 % |
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 |
||
8 | class Attribute |
||
9 | # @!attribute |
||
10 | # @return [AMA::Entity::Mapper::Type::Concrete] |
||
11 | attr_accessor :owner |
||
12 | # @!attribute |
||
13 | # @return [Symbol] |
||
14 | attr_accessor :name |
||
15 | # @!attribute types List of possible types attribute may take |
||
16 | # @return [Array<AMA::Entity::Mapper::Type>] |
||
17 | attr_accessor :types |
||
18 | # @!attribute virtual |
||
19 | # @return [TrueClass, FalseClass] |
||
20 | attr_accessor :virtual |
||
21 | # @!attribute sensitive |
||
22 | # @return [TrueClass, FalseClass] |
||
23 | attr_accessor :sensitive |
||
24 | # @!attribute nullable |
||
25 | # @return [TrueClass, FalseClass] |
||
26 | attr_accessor :nullable |
||
27 | # @!attribute values Possible values this attribute can take |
||
28 | # @return [Array] |
||
29 | attr_accessor :values |
||
30 | # @!attribute validator Ruby block that validates resulting value |
||
31 | # @return [Proc] |
||
32 | attr_accessor :validator |
||
33 | |||
34 | def initialize(owner, name, *types, **options) |
||
35 | @owner = owner |
||
36 | @name = name |
||
37 | @types = types |
||
38 | @nullable = options.fetch(:nullable, true) |
||
39 | @sensitive = options.fetch(:sensitive, false) |
||
40 | @virtual = options.fetch(:virtual, false) |
||
41 | end |
||
42 | |||
43 | def hash |
||
44 | @owner.hash ^ @name.hash |
||
45 | end |
||
46 | |||
47 | View Code Duplication | def eql?(other) |
|
|
|||
48 | return false unless other.is_a?(self.class) |
||
49 | @owner == other.owner && @name == other.name |
||
50 | end |
||
51 | |||
52 | def ==(other) |
||
53 | eql?(other) |
||
54 | end |
||
55 | |||
56 | def to_s |
||
57 | "Attribute :#{name} (#{owner})" |
||
58 | end |
||
59 | end |
||
60 | end |
||
64 |