Class: WebFunction::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/web_function/attribute.rb

Overview

# Attribute

An Attribute defines an output field that may be produced and returned by a Web Function endpoint.

See the [attributes section] on the Web Function website for more details about attribute definitions, recognized keys, and usage.

[0]: webfunction.org/package#attributes

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ Attribute

Returns a new instance of Attribute.



15
16
17
# File 'lib/web_function/attribute.rb', line 15

def initialize(attribute)
  @attribute = attribute
end

Instance Method Details

#docsString

## Docs

A markdown string describing this attribute and its purpose in the output object. Used by documentation tools, and highly recommended.

Returns:

  • (String)


96
97
98
# File 'lib/web_function/attribute.rb', line 96

def docs
  @attribute["docs"].to_s
end

#flagsArray<String>

## Flags

An array of attribute flags. Flags describe special characteristics or behaviors of attributes. See the [available flags section] for complete list and documentation.

[2]: webfunction.org/package#available-flags

Returns:

  • (Array<String>)


85
86
87
# File 'lib/web_function/attribute.rb', line 85

def flags
  [*@attribute["flags"]].map(&:to_s)
end

#hintString?

## Hint

A string hinting about the semantics of this attribute. See the

hints section][1

for possible values and documentation tooling guidance.

[1]: webfunction.org/package#hints

Returns:

  • (String, nil)


56
57
58
# File 'lib/web_function/attribute.rb', line 56

def hint
  @attribute["hint"]
end

#nameString

## Name

The name of the attribute as it will appear in the endpoint’s output object.

Returns:

  • (String)


26
27
28
# File 'lib/web_function/attribute.rb', line 26

def name
  @attribute["name"]
end

#typeString

## Type

The type of value returned for this attribute. Must be one of:

- object
- array
- string
- number
- boolean

This is a required string.

Returns:

  • (String)


43
44
45
# File 'lib/web_function/attribute.rb', line 43

def type
  @attribute["type"]
end

#valuesArray

## Values

An array specifying the exact, case-sensitive values that may be returned for this attribute. Each value in the values array must conform to the data type specified in the “type” key.

This is useful for attributes that can only take a select set of values (enums or constants).

Returns:

  • (Array)


71
72
73
# File 'lib/web_function/attribute.rb', line 71

def values
  [*@attribute["values"]]
end