Class: WebFunction::Argument
- Inherits:
-
Object
- Object
- WebFunction::Argument
- Includes:
- Flaggable
- Defined in:
- lib/web_function/argument.rb
Overview
Arguments are used to define Web Function Endpoint request parameters.
See the arguments section on the Web Function website for more details.
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.
-
#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:, 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:, group: nil, choices: [], flags: [], docs: nil) ⇒ Argument
Returns a new instance of Argument.
13 14 15 16 17 18 19 20 |
# File 'lib/web_function/argument.rb', line 13 def initialize(name:, type:, group: nil, choices: [], flags: [], docs: nil) @name = name @type = Type.parse(type) @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.
99 100 101 |
# File 'lib/web_function/argument.rb', line 99 def choices @choices end |
#docs ⇒ String (readonly)
Description of the argument. It must be formatted as markdown.
105 106 107 |
# File 'lib/web_function/argument.rb', line 105 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.
89 90 91 |
# File 'lib/web_function/argument.rb', line 89 def group @group end |
#name ⇒ String (readonly)
The name of the argument.
70 71 72 |
# File 'lib/web_function/argument.rb', line 70 def name @name end |
#type ⇒ String (readonly)
The type of the argument. It must be one of:
- object
- array
- string
- number
- boolean
82 83 84 |
# File 'lib/web_function/argument.rb', line 82 def type @type end |
Class Method Details
.from_array(arguments) ⇒ Array<Argument>
59 60 61 62 63 |
# File 'lib/web_function/argument.rb', line 59 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.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/web_function/argument.rb', line 29 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"], 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.
119 120 121 |
# File 'lib/web_function/argument.rb', line 119 def optional? !required? end |
#required? ⇒ Boolean
Whether the argument is required.
111 112 113 |
# File 'lib/web_function/argument.rb', line 111 def required? flag?("required") end |