Class: SoberSwag::Nodes::Primitive
- Defined in:
- lib/sober_swag/nodes/primitive.rb
Overview
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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#metadata ⇒ Hash
readonly
Metadata associated with the contained value.
-
#value ⇒ Object
readonly
The contained value.
Instance Method Summary collapse
-
#cata {|node| ... } ⇒ Object
As this is a root node, we actually call the block directly.
-
#deconstruct ⇒ Array(Object, Hash)
Deconstructs to the value and the metadata.
-
#deconstruct_keys(_) ⇒ Hash{Symbol => Object, Hash}
Wraps the attributes in a hash.
-
#initialize(value, metadata = {}) ⇒ Primitive
constructor
A new instance of Primitive.
-
#map(&block) ⇒ Object
This will actually map over #value.
Methods inherited from Base
Constructor Details
#initialize(value, metadata = {}) ⇒ Primitive
Returns a new instance of Primitive.
14 15 16 17 |
# File 'lib/sober_swag/nodes/primitive.rb', line 14 def initialize(value, = {}) @value = value @metadata = end |
Instance Attribute Details
#metadata ⇒ Hash (readonly)
Returns metadata associated with the contained value.
25 26 27 |
# File 'lib/sober_swag/nodes/primitive.rb', line 25 def @metadata end |
#value ⇒ Object (readonly)
Returns the contained value.
21 22 23 |
# File 'lib/sober_swag/nodes/primitive.rb', line 21 def value @value end |
Instance Method Details
#cata {|node| ... } ⇒ Object
As this is a root node, we actually call the block directly.
57 58 59 |
# File 'lib/sober_swag/nodes/primitive.rb', line 57 def cata(&block) block.call(self.class.new(value, )) end |
#deconstruct ⇒ Array(Object, Hash)
Deconstructs to the value and the metadata.
39 40 41 |
# File 'lib/sober_swag/nodes/primitive.rb', line 39 def deconstruct [value, ] end |
#deconstruct_keys(_) ⇒ Hash{Symbol => Object, Hash}
Wraps the attributes in a hash.
48 49 50 |
# File 'lib/sober_swag/nodes/primitive.rb', line 48 def deconstruct_keys(_) { value: value, metadata: } end |