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

Denormalizer.denormalize()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
1
# frozen_string_literal: true
2
3
# rubocop:disable Lint/UnusedMethodArgument
4
5
require_relative 'interface'
6
7
module AMA
8
  module Entity
9
    class Mapper
10
      module API
11
        # This interface depicts class denormalizer - processor, responsible
12
        # for populating entity from low-level primitives and context
13
        class Denormalizer < Interface
14
          # :nocov:
15
          # This methods accepts input data and type and creates corresponding
16
          # entity. If necessary, type's factory may be called to instantiate
17
          # entity.
18
          #
19
          # Method is provided with context and fallback block (with same
20
          # signature) that allows to use default denormalization process. This
21
          # allows denormalizer to use context to populate entity or use
22
          # fallback block before or after processing:
23
          #
24
          # ```ruby
25
          # data = { id: data } if data.is_a?(String) || data.is_a?(Symbol)
26
          # yield(data, type, context)
27
          # entity.id = entity.id || context.path.current.name
28
          # entity
29
          # ```
30
          #
31
          # This method should not attempt to denormalize attributes, since that
32
          # would be taken care of by mapper itself.
33
          #
34
          # @param [Object] data
35
          # @param [AMA::Entity::Mapper::Type::Concrete] type
36
          # @param [AMA::Entity::Mapper::Context] context
37
          # @param [Proc] block
38
          # @return [Object]
39
          def denormalize(data, type, context = nil, &block)
40
            abstract_method
41
          end
42
          # :nocov:
43
        end
44
      end
45
    end
46
  end
47
end
48