Module: StubRequests::Concerns::ArgumentValidation
- Extended by:
- ArgumentValidation
- Included in:
- ArgumentValidation, Property, Property::Validator
- Defined in:
- lib/stub_requests/concerns/argument_validation.rb
Overview
Module ArgumentValidation provides validation of method arguments
Instance Method Summary collapse
-
#validate!(name:, value:, type:) ⇒ void
Require the value to be any of the types past in.
- #validate_type!(name, value, type) ⇒ Object
Instance Method Details
#validate!(name:, value:, type:) ⇒ void
This method returns an undefined value.
Require the value to be any of the types past in
31 32 33 34 |
# File 'lib/stub_requests/concerns/argument_validation.rb', line 31 def validate!(name:, value:, type:) validate_type!(:name, name, [Symbol, String]) unless name validate_type!(name, value, type) if type end |
#validate_type!(name, value, type) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/stub_requests/concerns/argument_validation.rb', line 36 def validate_type!(name, value, type) expected_types = Array(type).flatten return if expected_types.any? { |is_a| value.is_a?(is_a) } raise StubRequests::InvalidArgumentType, name: name, actual: value.class, expected: expected_types end |