Sha256: 77a53dc8d6b7de92aaef140d719c56092ba162a89cd3aef7d565cd8656a810f5

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

module Cts
  module Mpx
    module Driver
      module Exceptions
        module_function

        # Raise an ArgumentError if the argument does not pass Validators.account_id?
        # @param [Object] argument argument to test if it is a valid account_id
        # @raise [ArgumentError] if the argument is not a valid account_id
        # @return [nil]
        def raise_unless_account_id(argument)
          raise ArgumentError, "#{argument} is not a valid account_id" unless Validators.account_id? argument

          nil
        end

        # Raise an ArgumentError if the argument is not of the supplied type
        # @param [Object] data argument to test if it is the correct type
        # @param [Object] type type to test for
        # @raise [ArgumentError] if the argument is not of the correct type
        # @return [nil]
        def raise_unless_argument_error?(data, type = nil, &block)
          raise(ArgumentError, "#{data || 'nil'} is not a valid #{type}") if Validators.argument_error?(data, type, &block)

          nil
        end

        # Raise an ArgumentError if the argument does not pass Validators.reference?
        # @param [Object] argument argument to test if it is a valid reference
        # @raise [ArgumentError] if the argument is not a valid reference
        # @return [nil]
        def raise_unless_reference?(argument)
          raise ArgumentError, "#{argument} is not a valid reference" unless Validators.reference? argument

          nil
        end

        # Raise an ArgumentError if the keyword is not supplied.
        # @param [Object] keyword keyword to assure is supplied
        # @raise [ArgumentError] if the keyword is not suppplied
        # @return [nil]
        def raise_unless_required_keyword?(a_binding, keyword)
          value = a_binding.local_variable_get(keyword)
          raise ArgumentError, "#{keyword} is a required keyword." unless value

          nil
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cts-mpx-1.1.1 lib/cts/mpx/driver/exceptions.rb
cts-mpx-1.1.0 lib/cts/mpx/driver/exceptions.rb