Class: SoberSwag::Nodes::Attribute
- Defined in:
- lib/sober_swag/nodes/attribute.rb
Overview
This is a node for one attribute of an object.
An object type is represented by a SoberSwag::Nodes::Object
full of these keys.
Instance Attribute Summary collapse
- #key ⇒ Symbol readonly
-
#meta ⇒ Hash
readonly
The metadata for this attribute.
-
#required ⇒ Boolean
readonly
True if this attribute must be set, false otherwise.
-
#value ⇒ Class
readonly
The type of this attribute.
Instance Method Summary collapse
- #cata(&block) ⇒ Object
- #deconstruct ⇒ Array(Symbol, Boolean, Class, Hash)
- #deconstruct_keys(_keys) ⇒ Hash
-
#initialize(key, required, value, meta = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #map(&block) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(key, required, value, meta = {}) ⇒ Attribute
Returns a new instance of Attribute.
14 15 16 17 18 19 |
# File 'lib/sober_swag/nodes/attribute.rb', line 14 def initialize(key, required, value, = {}) @key = key @required = required @value = value @meta = end |
Instance Attribute Details
#key ⇒ Symbol (readonly)
42 43 44 |
# File 'lib/sober_swag/nodes/attribute.rb', line 42 def key @key end |
#meta ⇒ Hash (readonly)
Returns the metadata for this attribute.
54 55 56 |
# File 'lib/sober_swag/nodes/attribute.rb', line 54 def @meta end |
#required ⇒ Boolean (readonly)
Returns true if this attribute must be set, false otherwise.
46 47 48 |
# File 'lib/sober_swag/nodes/attribute.rb', line 46 def required @required end |
#value ⇒ Class (readonly)
Returns the type of this attribute.
50 51 52 |
# File 'lib/sober_swag/nodes/attribute.rb', line 50 def value @value end |
Instance Method Details
#cata(&block) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/sober_swag/nodes/attribute.rb', line 64 def cata(&block) block.call( self.class.new( key, required, value.cata(&block), ) ) end |
#deconstruct ⇒ Array(Symbol, Boolean, Class, Hash)
Deconstruct into the #key, #required, #value, and #meta attributes of this SoberSwag::Nodes::Attribute object.
26 27 28 |
# File 'lib/sober_swag/nodes/attribute.rb', line 26 def deconstruct [key, required, value, ] end |
#deconstruct_keys(_keys) ⇒ Hash
36 37 38 |
# File 'lib/sober_swag/nodes/attribute.rb', line 36 def deconstruct_keys(_keys) { key: key, required: required, value: value, meta: } end |
#map(&block) ⇒ Object
58 59 60 |
# File 'lib/sober_swag/nodes/attribute.rb', line 58 def map(&block) self.class.new(key, required, value.map(&block), ) end |