Module: CinnamonSerial::Dsl

Included in:
Base
Defined in:
lib/cinnamon_serial/dsl.rb

Overview

This module includes all the class-level methods used to specify serializers.

Instance Method Summary collapse

Instance Method Details

#cinnamon_serial_specificationObject



13
14
15
# File 'lib/cinnamon_serial/dsl.rb', line 13

def cinnamon_serial_specification
  @cinnamon_serial_specification ||= Specification.new
end

#hydrate(&block) ⇒ Object



23
24
25
26
27
# File 'lib/cinnamon_serial/dsl.rb', line 23

def hydrate(&block)
  cinnamon_serial_specification.hydrate(block)

  nil
end

#inherited_cinnamon_serial_specificationObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cinnamon_serial/dsl.rb', line 29

def inherited_cinnamon_serial_specification
  return @inherited_cinnamon_serial_specification if @inherited_cinnamon_serial_specification

  attribute_map  = {}
  hydrate_blocks = []

  # We need to reverse this so parents go first.
  ancestors.reverse_each do |ancestor|
    next unless ancestor.respond_to?(:cinnamon_serial_specification)

    specification = ancestor.cinnamon_serial_specification

    attribute_map.merge!(specification.attribute_map)
    hydrate_blocks += specification.hydrate_blocks
  end

  @inherited_cinnamon_serial_specification = Specification.new(
    attribute_map: attribute_map,
    hydrate_blocks: hydrate_blocks
  )
end

#serialize(*keys) ⇒ Object



17
18
19
20
21
# File 'lib/cinnamon_serial/dsl.rb', line 17

def serialize(*keys)
  cinnamon_serial_specification.set(keys)

  nil
end