module Erratum
Constants
- VERSION
Public Class Methods
build(original_error, overrides = {})
click to toggle source
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# File lib/erratum.rb, line 30 def self.build(original_error, overrides = {}) overrides = overrides.symbolize_keys original_error_name = error_name(original_error) build_error_name = mapped_error_name(original_error_name) build_error_class = error_class(build_error_name) if original_error.is_a?(Class) && original_error < ::Erratum::Error original_error.new(overrides) elsif original_error.is_a?(String) build_error_class.new(overrides) elsif original_error.is_a?(::Erratum::Error) original_source = original_error.source.symbolize_keys build_error_class.new(original_source.merge(overrides)) elsif build_error_class.respond_to?(:convert) build_error_class.convert(original_error, overrides) elsif build_error_class < Exception && build_error_class == original_error.class ::Erratum::Errors::RuntimeError.wrap(original_error) else ::Erratum::Errors::RuntimeError.new( message: "#{build_error_class.name}: #{original_error.inspect}", ) end end
configuration()
click to toggle source
# File lib/erratum/configuration.rb, line 51 def self.configuration Configuration.instance end
configure() { |configuration| ... }
click to toggle source
# File lib/erratum/configuration.rb, line 47 def self.configure yield configuration end
error_class(name)
click to toggle source
# File lib/erratum.rb, line 86 def self.error_class(name) if const_defined?("::#{name}") Object.const_get(name) else Object.const_get("Erratum::Errors::#{name}") end rescue NameError => error Kernel.raise( error.exception(<<~HEREDOC.chomp.tr("\n", ' ')), Erratum could not find an error class with either the name "#{name}" or with the name "Erratum::Errors::#{name}". Please verify the spelling and that the class is loaded. HEREDOC ) end
error_name(error)
click to toggle source
# File lib/erratum.rb, line 69 def self.error_name(error) if error.is_a?(String) error.gsub(/\A::/, '') elsif error.is_a? Class error.name else error.class.name end end
fail(error_type, **args)
click to toggle source
# File lib/erratum.rb, line 63 def self.fail(error_type, **args) Kernel.fail build(error_type, **args) end
mapped_error_name(name)
click to toggle source
# File lib/erratum.rb, line 79 def self.mapped_error_name(name) configuration .error_mappings .fetch(name, name) .gsub(/\A::/, '') end
raise(error_type, **args)
click to toggle source
rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# File lib/erratum.rb, line 59 def self.raise(error_type, **args) Kernel.fail build(error_type, **args) end