Module: Rescuer
- Defined in:
- lib/rescuer.rb,
lib/rescuer/version.rb
Defined Under Namespace
Constant Summary collapse
- DEFAULT_EXCEPTIONS_TO_RESCUE =
[StandardError]
- VERSION =
The current version of this gem
'0.1.0'
Class Method Summary collapse
Class Method Details
.new(*exceptions) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rescuer.rb', line 6 def new(*exceptions) raise ArgumentError, 'no block given' unless block_given? passed = exceptions && exceptions.flatten.compact to_rescue, to_pass = if passed.nil? || passed.empty? then [DEFAULT_EXCEPTIONS_TO_RESCUE, nil] else [passed, passed] end begin value = yield Success.new(value, to_pass) rescue *to_rescue => error Failure.new(error, to_pass) end end |