Module: ExceptionUtilities
- Defined in:
- lib/exception_utilities.rb,
lib/exception_utilities/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"1.0.0"
Class Method Summary collapse
- .exception_matcher(&block) ⇒ Object
- .exceptions_ignoring_eval(*modules) ⇒ Object
- .exceptions_with_message(pattern, *exception_classes) ⇒ Object
Class Method Details
.exception_matcher(&block) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/exception_utilities.rb', line 19 def exception_matcher(&block) Module.new do (class << self; self; end).class_eval do define_method(:===, &block) end end end |
.exceptions_ignoring_eval(*modules) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/exception_utilities.rb', line 8 def exceptions_ignoring_eval(*modules) unless modules.all? {|ec| Module === ec } raise Error, 'only Module instances are accepted' end begin yield rescue *modules => exception exception end end |
.exceptions_with_message(pattern, *exception_classes) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/exception_utilities.rb', line 27 def (pattern, *exception_classes) exception_classes << StandardError if exception_classes.empty? exception_matcher do |exception| case exception when *exception_classes pattern === exception. rescue false else false end end end |