Module: AMA::Entity::Mapper::Mixin::SuppressionSupport
- Includes:
- Errors
- Included in:
- Engine::RecursiveMapper
- Defined in:
- lib/ama-entity-mapper/mixin/suppression_support.rb
Overview
Special module with method for playing with error suppression
Instance Method Summary collapse
-
#successful(enumerator, error = StandardError, ctx = nil) ⇒ Object
Enumerates elements in enumerator, applying block to each one, returning result or suppressing specified error.
Methods included from Errors
#compliance_error, #mapping_error, #raise_if_internal, #validation_error
Instance Method Details
#successful(enumerator, error = StandardError, ctx = nil) ⇒ Object
Enumerates elements in enumerator, applying block to each one, returning result or suppressing specified error. If no element has succeeded, raises last error.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ama-entity-mapper/mixin/suppression_support.rb', line 20 def successful(enumerator, error = StandardError, ctx = nil) suppressed = [] enumerator.each do |*args| begin return yield(*args) rescue error => e ctx.logger.debug("#{e.class} raised: #{e.message}") if ctx suppressed.push(e) end end compliance_error('Empty enumerator passed') if suppressed.empty? raise suppressed.last end |