Sha256: 2808ce624d5b3255df6974c823455b7ec8bdf0b49588c7092678a00360eeba73
Contents?: true
Size: 1.27 KB
Versions: 2
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true require "addressable/uri" require "public_suffix" # # Abstraction over WebMock to reduce duplication # # @author Mikael Henriksson <mikael@zoolutions.se> # @since 0.1.0 # module StubRequests # # Module ArgumentValidation provides validation of method arguments # # @author Mikael Henriksson <mikael@zoolutions.se> # module ArgumentValidation extend self # # Require the value to be any of the types past in # # # @param [Symbol] name the name of the argument # @param [Object] value the actual value of the argument # @param [Array, Class, Module] type nil the expected argument value class # # @raise [InvalidArgumentType] when the value is disallowed # # @return [void] # # :reek:UtilityFunction def validate!(name:, value:, type:) validate_type!(:name, name, [Symbol, String]) unless name validate_type!(name, value, type) if type end # :reek:UtilityFunction 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stub_requests-0.1.4 | lib/stub_requests/argument_validation.rb |
stub_requests-0.1.3 | lib/stub_requests/argument_validation.rb |