Sha256: 8154f0c005b0569f24416a954c7696f7db5e26951c383cbe18a7f0c201f2b9e8

Contents?: true

Size: 874 Bytes

Versions: 5

Compression:

Stored size: 874 Bytes

Contents

# frozen_string_literal: true

module Yoti
  class Validation
    #
    # @param value
    # @param [String] name
    #
    def self.assert_not_nil(value, name)
      return unless value.nil?

      raise(ArgumentError, "#{name} must not be nil")
    end

    #
    # @param [Class] type
    # @param value
    # @param [String] name
    # @param [Boolean] nilable
    #
    def self.assert_is_a(type, value, name, nilable = false)
      return if nilable && value.nil?
      return if value.is_a?(type)

      raise(ArgumentError, "#{name} must be a #{type.name}")
    end

    #
    # @param [Symbol] method
    # @param value
    # @param [String] name
    #
    def self.assert_respond_to(method, value, name)
      assert_not_nil(value, name)

      return if value.respond_to?(method)

      raise(ArgumentError, "#{name} must respond to #{method}")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yoti-1.10.0 lib/yoti/util/validation.rb
yoti-1.9.0 lib/yoti/util/validation.rb
yoti-1.8.0 lib/yoti/util/validation.rb
yoti-1.7.1 lib/yoti/util/validation.rb
yoti-1.7.0 lib/yoti/util/validation.rb