class SoberSwag::Nodes::Primitive
Root node of the tree. This contains “primitive values.” Initially, this is probably the types of attributes or array elements or whatever. As we use {#cata} to transform this, it will start containing swagger-compatible type objects.
This node can contain metadata as well.
Attributes
@return [Hash] metadata associated with the contained value.
@return [Object] the contained value
Public Class Methods
@param value [Object] the primitive value to store @param metadata [Hash] the metadata
# File lib/sober_swag/nodes/primitive.rb, line 14 def initialize(value, metadata = {}) @value = value @metadata = metadata end
Public Instance Methods
@see SoberSwag::Nodes::Base#cata
As this is a root node, we actually call the block directly. @yieldparam node [SoberSwag::Nodes::Primitive] this node. @return whatever the block returns.
# File lib/sober_swag/nodes/primitive.rb, line 57 def cata(&block) block.call(self.class.new(value, metadata)) end
Deconstructs to the value and the metadata.
@return [Array(Object
, Hash)] containing value and metadata.
# File lib/sober_swag/nodes/primitive.rb, line 39 def deconstruct [value, metadata] end
Wraps the attributes in a hash.
@return [Hash{Symbol => Object
, Hash}]
{#value} in `value:`, {#metadata} in `metadata:`
# File lib/sober_swag/nodes/primitive.rb, line 48 def deconstruct_keys(_) { value: value, metadata: metadata } end
@see SoberSwag::Nodes::Base#map
This will actually map over {#value}.
# File lib/sober_swag/nodes/primitive.rb, line 31 def map(&block) self.class.new(block.call(value), metadata.dup) end