Completed
Push — master ( 308a2c...1aebdd )
by Fike
01:00
created

HashTupleType.initialize()   A

Complexity

Conditions 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
1
# frozen_string_literal: true
2
3
require_relative '../../type'
4
require_relative '../aux/hash_tuple'
5
6
module AMA
7
  module Entity
8
    class Mapper
9
      class Type
10
        module BuiltIn
11
          # Pair class definition
12
          class HashTupleType < Type
13
            def initialize
14
              super(Aux::HashTuple, virtual: true)
15
16
              attribute!(:key, parameter!(:K))
17
              attribute!(:value, parameter!(:V))
18
19
              enumerator_block do |entity, type, *|
20
                ::Enumerator.new do |yielder|
21
                  yielder << [type.attributes[:key], entity.key, nil]
22
                  yielder << [type.attributes[:value], entity.value, nil]
23
                end
24
              end
25
            end
26
27
            INSTANCE = new
28
          end
29
        end
30
      end
31
    end
32
  end
33
end
34