class SoberSwag::Nodes::Attribute

This is a node for one attribute of an object. An object type is represented by a `SoberSwag::Nodes::Object` full of these keys.

Attributes

key[R]

@return [Symbol]

meta[R]

@return [Hash] the metadata for this attribute.

required[R]

@return [Boolean] true if this attribute must be set, false otherwise.

value[R]

@return [Class] the type of this attribute

Public Class Methods

new(key, required, value, meta = {}) click to toggle source

@param key [Symbol] the key of this attribute @param required [Boolean] if this attribute must be set or not @param value [Class] the type of this attribute @param meta [Hash] the metadata associated with this attribute

# File lib/sober_swag/nodes/attribute.rb, line 14
def initialize(key, required, value, meta = {})
  @key = key
  @required = required
  @value = value
  @meta = meta
end

Public Instance Methods

cata(&block) click to toggle source

@see SoberSwag::Nodes::Base#cata

# File lib/sober_swag/nodes/attribute.rb, line 64
def cata(&block)
  block.call(
    self.class.new(
      key, required, value.cata(&block), meta
    )
  )
end
deconstruct() click to toggle source

Deconstruct into the {#key}, {#required}, {#value}, and {#meta} attributes of this {Attribute} object.

@return [Array(Symbol, Boolean, Class, Hash)] the attributes of this object

# File lib/sober_swag/nodes/attribute.rb, line 26
def deconstruct
  [key, required, value, meta]
end
deconstruct_keys(_keys) click to toggle source

Deconstructs into {#key}, {#required}, {#value}, and {#meta} attributes, as a hash with the attribute names as the keys.

@param _keys [void] ignored @return [Hash] the attributes as keys.

# File lib/sober_swag/nodes/attribute.rb, line 36
def deconstruct_keys(_keys)
  { key: key, required: required, value: value, meta: meta }
end
map(&block) click to toggle source

@see SoberSwag::Nodes::Base#map

# File lib/sober_swag/nodes/attribute.rb, line 58
def map(&block)
  self.class.new(key, required, value.map(&block), meta)
end