Completed
Push — dev ( 73864e...ffd8f7 )
by Fike
38s
created

Attribute   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 7.69 %

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
dl 4
loc 52
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A to_s() 0 3 1
A initialize() 0 8 1
A ==() 0 3 1
A eql? 4 4 2
A hash() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

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
2
3
module AMA
4
  module Entity
5
    class Mapper
6
      class Type
7
        # Stores data about single type attribute
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)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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
61
    end
62
  end
63
end
64