| Total Complexity | 1 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # frozen_string_literal: true |
||
| 13 | class Normalizer < Interface |
||
| 14 | # :nocov: |
||
| 15 | # This method takes in provided entity and it's specific type and |
||
| 16 | # should return low-level representation of this entity (most |
||
| 17 | # commonly, hash of attributes). This normalizer has an option to |
||
| 18 | # fall back on default normalization process (using `block.call()` |
||
| 19 | # with same signature). Such feature allows to use normalizer as |
||
| 20 | # pre- or post-processor, either altering incoming entity or polishing |
||
| 21 | # result: |
||
| 22 | # |
||
| 23 | # ```ruby |
||
| 24 | # data = block.call(entity, type, context) |
||
| 25 | # data[:parent] = entity.parent.id # replacing parent with it's id |
||
| 26 | # data |
||
| 27 | # ``` |
||
| 28 | # |
||
| 29 | # It is implied that normalizers *work only on single level*, which |
||
| 30 | # means that they should not process underlying attributes. In the |
||
| 31 | # example above, that would mean that without additional processing, |
||
| 32 | # `data[:parent]` would have parent entity unchanged. |
||
| 33 | # |
||
| 34 | # @param [Object] entity |
||
| 35 | # @param [AMA::Entity::Mapper::Type::Concrete] type |
||
| 36 | # @param [AMA::Entity::Mapper::Context] context |
||
| 37 | # @param [Proc] block |
||
| 38 | # @return [Object] |
||
| 39 | def normalize(entity, type, context = nil, &block) |
||
| 40 | abstract_method |
||
| 41 | end |
||
| 42 | # :nocov: |
||
| 43 | end |
||
| 44 | end |
||
| 48 |