Sha256: a552f83120885fe628f3074a5dbe35412ff89682b4f862f67b4beaf5c94906c1
Contents?: true
Size: 821 Bytes
Versions: 12
Compression:
Stored size: 821 Bytes
Contents
# frozen_string_literal: true module MuchRails; end class MuchRails::ServiceValidationErrors attr_reader :hash def initialize @hash = {} end def add(exception_class, &block) unless exception_class && exception_class < Exception raise(ArgumentError, "#{exception_class} is not an Exception") end @hash[exception_class] = block end def exception_classes @hash.keys end def result_for(ex) result_proc = nil exception_class = ex.class loop do result_proc = @hash[exception_class] break unless result_proc.nil? exception_class = if exception_class.superclass.nil? raise ArgumentError, "#{ex.class} hasn't been configured" else exception_class.superclass end end result_proc.call(ex) end end
Version data entries
12 entries across 12 versions & 1 rubygems