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

metadata[R]

@return [Hash] metadata associated with the contained value.

value[R]

@return [Object] the contained value

Public Class Methods

new(value, metadata = {}) click to toggle source

@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

cata(&block) click to toggle source

@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
deconstruct() click to toggle source

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
deconstruct_keys(_) click to toggle source

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
map(&block) click to toggle source

@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