class CinnamonSerial::Specification

A Specification is a group of attribute mappings and custom code blocks to execute for a serializer.

Attributes

attribute_map[R]
hydrate_blocks[R]

Public Class Methods

new(attribute_map: {}, hydrate_blocks: []) click to toggle source
# File lib/cinnamon_serial/specification.rb, line 16
def initialize(attribute_map: {}, hydrate_blocks: [])
  @attribute_map  = attribute_map
  @hydrate_blocks = hydrate_blocks
end

Public Instance Methods

hydrate(block) click to toggle source
# File lib/cinnamon_serial/specification.rb, line 34
def hydrate(block)
  @hydrate_blocks << block

  nil
end
set(*keys) click to toggle source
# File lib/cinnamon_serial/specification.rb, line 21
def set(*keys)
  keys = keys.flatten

  # We have been sent options
  options = Resolver.new(keys.last.is_a?(Hash) ? keys.pop : {})

  raise ArgumentError, 'keys cannot be empty' if keys.empty?

  keys.each { |key| @attribute_map[key.to_s] = options }

  nil
end