Sha256: 4b08e805e8d7ec1d64fac643afd156560daf1adb00d9818837e13b38a29f9fe7

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

#
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module CinnamonSerial
  # This module includes all the class-level methods used to specify serializers.
  module Dsl
    def cinnamon_serial_specification
      @cinnamon_serial_specification ||= Specification.new
    end

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

      nil
    end
    # <b>DEPRECATED:</b> Please use <tt>serialize</tt> instead.
    alias present serialize

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

      nil
    end

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cinnamon_serial-1.0.1 lib/cinnamon_serial/dsl.rb
cinnamon_serial-1.0.0 lib/cinnamon_serial/dsl.rb