Class: WebFunction::Argument
- Inherits:
-
Object
- Object
- WebFunction::Argument
- Includes:
- Flaggable
- Defined in:
- lib/web_function/argument.rb
Overview
Instance Attribute Summary collapse
-
#choices ⇒ Array
readonly
An array specifying the exact, case-sensitive values that are permitted for this argument.
-
#docs ⇒ String
readonly
Description of the argument.
-
#group ⇒ String
readonly
A name used to categorize or group similar arguments together.
-
#hint ⇒ String
readonly
A hint that further defines what kind of value to expect for an argument.
-
#name ⇒ String
readonly
The name of the argument.
-
#type ⇒ String
readonly
The type of the argument.
Attributes included from Flaggable
Class Method Summary collapse
-
.from_array(arguments) ⇒ Array<Argument>
Instantiate a collection of Argument from an array of hash, typically coming from a Package.
-
.from_hash(argument) ⇒ Argument?
Instantiate a new Argument from a hash, typically coming from a Package.
Instance Method Summary collapse
-
#initialize(name:, type:, hint: nil, group: nil, choices: [], flags: [], docs: nil) ⇒ Argument
constructor
A new instance of Argument.
-
#optional? ⇒ Boolean
Whether the argument is optional.
-
#required? ⇒ Boolean
Whether the argument is required.
Methods included from Flaggable
Constructor Details
#initialize(name:, type:, hint: nil, group: nil, choices: [], flags: [], docs: nil) ⇒ Argument
Returns a new instance of Argument.
13 14 15 16 17 18 19 20 21 |
# File 'lib/web_function/argument.rb', line 13 def initialize(name:, type:, hint: nil, group: nil, choices: [], flags: [], docs: nil) @name = name @type = type @hint = hint @group = group @choices = choices @flags = flags @docs = docs.to_s end |
Instance Attribute Details
#choices ⇒ Array (readonly)
An array specifying the exact, case-sensitive values that are permitted for this argument. Each value in the choices array must conform to the data type specified in the argument’s type key.
Note that if the argument type is array, choices may contain strings or numbers representing the allowed values that can be included in the array.
111 112 113 |
# File 'lib/web_function/argument.rb', line 111 def choices @choices end |
#docs ⇒ String (readonly)
Description of the argument. It must be formatted as markdown.
117 118 119 |
# File 'lib/web_function/argument.rb', line 117 def docs @docs end |
#group ⇒ String (readonly)
A name used to categorize or group similar arguments together. This should be used by documentation tools to organize related arguments.
101 102 103 |
# File 'lib/web_function/argument.rb', line 101 def group @group end |
#hint ⇒ String (readonly)
A hint that further defines what kind of value to expect for an argument.
See the [hints section] on the Web Function website for the full list of possible hints.
94 95 96 |
# File 'lib/web_function/argument.rb', line 94 def hint @hint end |
#name ⇒ String (readonly)
The name of the argument.
72 73 74 |
# File 'lib/web_function/argument.rb', line 72 def name @name end |
#type ⇒ String (readonly)
The type of the argument. It must be one of:
-
object
-
array
-
string
-
number
-
boolean
84 85 86 |
# File 'lib/web_function/argument.rb', line 84 def type @type end |
Class Method Details
.from_array(arguments) ⇒ Array<Argument>
61 62 63 64 65 |
# File 'lib/web_function/argument.rb', line 61 def from_array(arguments) Utils.normalize_array arguments do |argument| from_hash(argument) end end |
.from_hash(argument) ⇒ Argument?
Instantiate a new Argument from a hash, typically coming from a Package.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/web_function/argument.rb', line 30 def from_hash(argument) unless argument.is_a?(Hash) return end unless argument["name"] return end unless argument["type"] return end new( name: argument["name"], type: argument["type"], hint: argument["hint"], group: argument["group"], choices: [*argument["choices"]], flags: Utils.normalize_array_of_strings(argument["flags"]), docs: argument["docs"], ) end |
Instance Method Details
#optional? ⇒ Boolean
Whether the argument is optional.
131 132 133 |
# File 'lib/web_function/argument.rb', line 131 def optional? !required? end |
#required? ⇒ Boolean
Whether the argument is required.
123 124 125 |
# File 'lib/web_function/argument.rb', line 123 def required? flag?("required") end |