Sha256: be98eacf5d6dfcb7be0dcc65d0b956d9686a0067e10d0ce396dcc32f1aba1dbe

Contents?: true

Size: 1.45 KB

Versions: 26

Compression:

Stored size: 1.45 KB

Contents

require_relative 'condition_utils'

module Antrapol
  module ToolRack
    module ExceptionUtils
      include Antrapol::ToolRack::ConditionUtils

      # raise_if_empty
      # Raise the given (or default if not given) exception if the val given is empty
      # val - variable/object that shall be tested for emptiness
      # message - message to be thrown if it is true
      # error - exception object to be thrown
      def raise_if_empty(val, message, error = StandardError)
        raise_error(message,error) if is_empty?(val)
      end # raise_if_empty
      alias_method :raise_if_empty?, :raise_if_empty

      # 
      # raise_if_false
      #
      def raise_if_false(bool, message, error = StandardError)
        if not bool
          raise_error(message,error)
        end 
      end # raise_if_false
      alias_method :raise_if_false?, :raise_if_false

      #
      # raise_if_true
      #
      def raise_if_true(bool, message, error = StandardError)
        raise_if_false(!bool, message, error)
      end # raise_if_true
      alias_method :raise_if_true?, :raise_if_true

      protected
      def raise_error(message, error = StandardError)
        if error.nil?
          if @default_exception.nil?
            raise StandardError, message
          else
            raise @default_exception, message
          end
        else
          raise error, message
        end
      end # raise_error
      
    end # ExceptionUtils
  end # ToolRack
end # Antrapol

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
toolrack-0.24.3 lib/toolrack/exception_utils.rb
toolrack-0.24.2 lib/toolrack/exception_utils.rb
toolrack-0.24.1 lib/toolrack/exception_utils.rb
toolrack-0.24.0 lib/toolrack/exception_utils.rb
toolrack-0.23.3 lib/toolrack/exception_utils.rb
toolrack-0.23.2 lib/toolrack/exception_utils.rb
toolrack-0.22.1 lib/toolrack/exception_utils.rb
toolrack-0.22.0 lib/toolrack/exception_utils.rb
toolrack-0.21.0 lib/toolrack/exception_utils.rb
toolrack-0.20.2 lib/toolrack/exception_utils.rb
toolrack-0.20.1 lib/toolrack/exception_utils.rb
toolrack-0.20.0 lib/toolrack/exception_utils.rb
toolrack-0.19.1 lib/toolrack/exception_utils.rb
toolrack-0.18.6 lib/toolrack/exception_utils.rb
toolrack-0.18.5 lib/toolrack/exception_utils.rb
toolrack-0.18.4 lib/toolrack/exception_utils.rb
toolrack-0.18.3 lib/toolrack/exception_utils.rb
toolrack-0.18.2 lib/toolrack/exception_utils.rb
toolrack-0.18.1 lib/toolrack/exception_utils.rb
toolrack-0.18.0 lib/toolrack/exception_utils.rb