Module: LedgerSync::Serialization::Mixin::ClassMethods

Defined in:
lib/ledger_sync/serialization/mixin.rb

Instance Method Summary collapse

Instance Method Details

#_attribute(args) ⇒ Object



38
39
40
# File 'lib/ledger_sync/serialization/mixin.rb', line 38

def _attribute(args)
  attributes.add(_build_attribute(args))
end

#_build_attribute(args) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ledger_sync/serialization/mixin.rb', line 42

def _build_attribute(args)
  block              = args.fetch(:block, nil)
  hash_attribute     = args.fetch(:hash_attribute, nil)
  resource_attribute = args.fetch(:resource_attribute, nil)
  resource_class     = args.fetch(:resource_class, nil)
  serializer         = args.fetch(:serializer, nil)
  type               = args.fetch(:type, nil)
  if_method          = args.fetch(:if, nil)

  attribute_class.new(
    block: block,
    hash_attribute: hash_attribute,
    if: if_method,
    resource_attribute: resource_attribute,
    resource_class: resource_class,
    serializer: serializer,
    type: type
  )
end

#attribute(_hash_attribute, _args = {}, &_block) ⇒ Serializer::Attribute

Class method for defining de/serializer attributes

Returns:

  • (Serializer::Attribute)

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/ledger_sync/serialization/mixin.rb', line 17

def attribute(_hash_attribute, _args = {}, &_block)
  raise NotImplementedError
end

#attribute_classObject

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/ledger_sync/serialization/mixin.rb', line 21

def attribute_class
  raise NotImplementedError
end

#attributesObject

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/ledger_sync/serialization/mixin.rb', line 25

def attributes
  raise NotImplementedError
end

#mapping(destination_attribute, args = {}) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/ledger_sync/serialization/mixin.rb', line 29

def mapping(destination_attribute, args = {})
  attribute(
    destination_attribute,
    {
      type: Type::MappingType.new(hash: args.fetch(:hash))
    }.merge(args.except(:hash))
  )
end