1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00
libkernaux/bindings/ruby/lib/kernaux/assert.rb

59 lines
1.2 KiB
Ruby
Raw Normal View History

2022-06-07 16:19:09 -04:00
# frozen_string_literal: true
# rubocop:disable Style/Documentation
begin; end
module KernAux
# Default callback for assertions.
# @see .assert_cb
DEFAULT_ASSERT_CB = @assert_cb = lambda { |file, line, msg|
raise AssertError, "#{file}:#{line}:#{msg}"
}
# @!scope class
##
# @!attribute [rw] assert_cb
# Panic callback.
#
# @return [Proc]
#
# @api unsafe
#
# @see .panic
# @see .assert_do
##
##
# Raise assertion with implicit file and line, retrieved from `caller`, and
# explicit message.
#
# @param msg [String] any message
# @return [nil]
#
# @raise [AssertError] if {.assert_cb} have not been changed
#
# @see .assert_do Explicit file and line.
#
def self.panic(msg)
file, line = caller(1..1).first.split(':')[0..1]
assert_do file, Integer(line), msg
end
##
# @!method assert_do(file, line, msg)
# Raise assertion with explicit file, line and message.
#
# @param file [String] file name, usually from `__FILE__`
# @param line [Integer] line number, usually from `__LINE__`
# @param msg [String] any message
# @return [nil]
#
# @raise [AssertError] if {.assert_cb} have not been changed
#
# @see .panic Implicit file and line
##
end
# rubocop:enable Style/Documentation