Class: Highway::Steps::Types::Any
- Inherits:
-
Object
- Object
- Highway::Steps::Types::Any
- Defined in:
- lib/highway/steps/types/any.rb
Overview
This class represents any parameter type. It can be used in parameters which should not perform any type checking.
Instance Method Summary collapse
-
#initialize(validate: nil) ⇒ Any
constructor
Initialize an instance.
-
#typecheck(value) ⇒ Object?
Typecheck and coerce a value if possible.
-
#typecheck_and_validate(value) ⇒ Object?
Typecheck and validate the value at the same time.
-
#validate(value) ⇒ Boolean
Validate the typechecked value against a custom validation block.
Constructor Details
#initialize(validate: nil) ⇒ Any
Initialize an instance.
19 20 21 |
# File 'lib/highway/steps/types/any.rb', line 19 def initialize(validate: nil) @validate = validate end |
Instance Method Details
#typecheck(value) ⇒ Object?
Typecheck and coerce a value if possible.
This method returns a typechecked and coerced value or ‘nil` if value has invalid type and can’t be coerced.
31 32 33 |
# File 'lib/highway/steps/types/any.rb', line 31 def typecheck(value) value end |
#typecheck_and_validate(value) ⇒ Object?
Typecheck and validate the value at the same time.
This method returns typechecked, coerced and validated value or ‘nil` if value has invalid type, can’t be coerced or is invalid.
56 57 58 59 |
# File 'lib/highway/steps/types/any.rb', line 56 def typecheck_and_validate(value) typechecked = typecheck(value) typechecked if !typechecked.nil? && validate(typechecked) end |
#validate(value) ⇒ Boolean
Validate the typechecked value against a custom validation block.
This method returns ‘true` if value is valid or `false` if value is invalid.
43 44 45 46 |
# File 'lib/highway/steps/types/any.rb', line 43 def validate(value) return true if @validate == nil @validate.call(value) end |