Total Complexity | 1 |
Total Lines | 19 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # frozen_string_literal: true |
||
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 |
||
38 |