Parameter.==()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
1
# frozen_string_literal: true
2
3
require_relative '../mixin/errors'
4
5
module AMA
6
  module Entity
7
    class Mapper
8
      class Type
9
        # This class represents parameter type - an unknown-until-runtime type
10
        # that belongs to particular other type. For example,
11
        # Hash<Symbol, Integer> may be described as Type(Hash) with
12
        # parameters _key: Symbol and _value: Integer
13
        class Parameter
14
          include Mixin::Errors
15
16
          # @!attribute type
17
          #   @return [AMA::Entity::Mapper::Type]
18
          attr_reader :owner
19
          # @!attribute id
20
          #   @return [Symbol]
21
          attr_reader :id
22
23
          # @param [AMA::Entity::Mapper::Type] owner
24
          # @param [Symbol] id
25
          def initialize(owner, id)
26
            @owner = owner
27
            @id = id
28
          end
29
30
          def instance?(_)
31
            false
32
          end
33
34
          def resolve_parameter(*)
35
            self
36
          end
37
38
          def resolved?
39
            false
40
          end
41
42
          def resolved!(context = nil)
43
            compliance_error("Type #{self} is not resolved", context: context)
44
          end
45
46
          def to_s
47
            "Parameter #{owner.type}.#{id}"
48
          end
49
50
          def to_def
51
            "#{owner.type}.#{id}"
52
          end
53
54
          def hash
55
            @owner.hash ^ @id.hash
56
          end
57
58
          def eql?(other)
59
            return false unless other.is_a?(self.class)
60
            @id == other.id && @owner == other.owner
61
          end
62
63
          def ==(other)
64
            eql?(other)
65
          end
66
        end
67
      end
68
    end
69
  end
70
end
71