Class: CinnamonSerial::Specification
- Inherits:
-
Object
- Object
- CinnamonSerial::Specification
- Defined in:
- lib/cinnamon_serial/specification.rb
Overview
A Specification is a group of attribute mappings and custom code blocks to execute for a serializer.
Instance Attribute Summary collapse
-
#attribute_map ⇒ Object
readonly
Returns the value of attribute attribute_map.
-
#hydrate_blocks ⇒ Object
readonly
Returns the value of attribute hydrate_blocks.
Instance Method Summary collapse
- #hydrate(block) ⇒ Object
-
#initialize(attribute_map: {}, hydrate_blocks: []) ⇒ Specification
constructor
A new instance of Specification.
- #set(*keys) ⇒ Object
Constructor Details
#initialize(attribute_map: {}, hydrate_blocks: []) ⇒ Specification
Returns a new instance of Specification.
16 17 18 19 |
# File 'lib/cinnamon_serial/specification.rb', line 16 def initialize(attribute_map: {}, hydrate_blocks: []) @attribute_map = attribute_map @hydrate_blocks = hydrate_blocks end |
Instance Attribute Details
#attribute_map ⇒ Object (readonly)
Returns the value of attribute attribute_map.
14 15 16 |
# File 'lib/cinnamon_serial/specification.rb', line 14 def attribute_map @attribute_map end |
#hydrate_blocks ⇒ Object (readonly)
Returns the value of attribute hydrate_blocks.
14 15 16 |
# File 'lib/cinnamon_serial/specification.rb', line 14 def hydrate_blocks @hydrate_blocks end |
Instance Method Details
#hydrate(block) ⇒ Object
34 35 36 37 38 |
# File 'lib/cinnamon_serial/specification.rb', line 34 def hydrate(block) @hydrate_blocks << block nil end |
#set(*keys) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cinnamon_serial/specification.rb', line 21 def set(*keys) keys = keys.flatten # We have been sent 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] = } nil end |