Class: Highway::Steps::Parameters::Single
- Defined in:
- lib/highway/steps/parameters/single.rb
Overview
This class is used in step definition classes to represent a single parameter of a step.
Instance Attribute Summary collapse
-
#default ⇒ Object?
readonly
Default value of the parameter.
-
#type ⇒ Highway::Steps::Types::*
readonly
Type of the parameter.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(name:, type:, required:, default: nil) ⇒ Single
constructor
Initialize an instance.
-
#typecheck_and_validate(value, interface:, keypath: []) ⇒ Object
Typecheck and validate a value of the parameter.
Methods inherited from Base
Constructor Details
#initialize(name:, type:, required:, default: nil) ⇒ Single
Initialize an instance.
24 25 26 27 28 29 30 |
# File 'lib/highway/steps/parameters/single.rb', line 24 def initialize(name:, type:, required:, default: nil) @name = name @required = required @type = type @default = default assert_default_value_valid() end |
Instance Attribute Details
#default ⇒ Object? (readonly)
Default value of the parameter.
40 41 42 |
# File 'lib/highway/steps/parameters/single.rb', line 40 def default @default end |
#type ⇒ Highway::Steps::Types::* (readonly)
Type of the parameter.
35 36 37 |
# File 'lib/highway/steps/parameters/single.rb', line 35 def type @type end |
Instance Method Details
#typecheck_and_validate(value, interface:, keypath: []) ⇒ Object
Typecheck and validate a value of the parameter.
This method returns typechecked, coerced and validated value or raises a fatal error if value has invalid type, can’t be coerced or is othweriwse invalid.
53 54 55 56 57 58 59 60 |
# File 'lib/highway/steps/parameters/single.rb', line 53 def typecheck_and_validate(value, interface:, keypath: []) typechecked = @type.typecheck_and_validate(value) if typechecked != nil typechecked else interface.fatal!("Invalid value: '#{value}' for parameter: '#{Utilities::keypath_to_s(keypath)}'.") end end |