Completed
Push — dev ( 36eb97...6cb2fc )
by Fike
01:01
created

Enumerator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A enumerate() 0 10 1
1
# frozen_string_literal: true
2
3
require_relative '../injector'
4
require_relative '../../context'
5
require_relative '../../mixin/reflection'
6
require_relative '../../path/segment'
7
8
module AMA
9
  module Entity
10
    class Mapper
11
      module API
12
        module Default
13
          # Default attribute enumerator
14
          class Enumerator < API::Injector
15
            include Mixin::Reflection
16
17
            INSTANCE = new
18
19
            # @param [Object] entity
20
            # @param [AMA::Entity::Mapper::Type] type
21
            # @param [AMA::Entity::Mapper::Context] _context
22
            def enumerate(entity, type, _context = nil)
23
              ::Enumerator.new do |yielder|
24
                type.attributes.values.reject(&:virtual).each do |attribute|
25
                  next unless object_variable_exists(entity, attribute.name)
26
                  value = object_variable(entity, attribute.name)
27
                  segment = Path::Segment.attribute(attribute.name)
28
                  yielder << [attribute, value, segment]
29
                end
30
              end
31
            end
32
          end
33
        end
34
      end
35
    end
36
  end
37
end
38