Total Complexity | 1 |
Total Lines | 20 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | # frozen_string_literal: true |
||
11 | class EntityValidator < API::EntityValidator |
||
12 | INSTANCE = new |
||
13 | |||
14 | # @param [Object] entity |
||
15 | # @param [Mapper::Type::Concrete] type |
||
16 | # @param [Mapper::Context] context |
||
17 | # @return [Array<Array<Attribute, String, Segment>] List of |
||
18 | # violations, combined with attribute and segment |
||
19 | def validate(entity, type, context) |
||
20 | enumerator = type.enumerator.enumerate(entity, type, context) |
||
21 | enumerator.flat_map do |attribute, value, segment = nil| |
||
22 | next_context = segment.nil? ? context : context.advance(segment) |
||
23 | validator = attribute.validator |
||
24 | violations = validator.validate(value, attribute, next_context) |
||
25 | violations.map do |violation| |
||
26 | [attribute, violation, segment] |
||
27 | end |
||
28 | end |
||
29 | end |
||
30 | end |
||
31 | end |
||
36 |