Sha256: 988dddbe83f9161c6b510febd612727b96504f2f8b13765062177d7785b4e6b8

Contents?: true

Size: 1.14 KB

Versions: 15

Compression:

Stored size: 1.14 KB

Contents

module Lev

  class ErrorTransferer

    def self.transfer(source, target_routine, input_mapper, fail_if_errors=false)
      case source
      when ActiveRecord::Base, Lev::Paramifier
        source.errors.each_with_type_and_message do |attribute, type, message|
          target_routine.nonfatal_error(
            code: type,
            data: {
              model: source,
              attribute: attribute
            },
            kind: :activerecord,
            message: message,
            offending_inputs: input_mapper.map(attribute)
          )
        end
      when Lev::Errors
        source.each do |error|
          target_routine.nonfatal_error(
            code: error.code,
            data: error.data,
            kind: error.kind,
            message: error.message,
            offending_inputs: input_mapper.map(error.offending_inputs)
          )
        end
      else
        raise Exception
      end

      # We add nonfatal errors above and then have this call here so that all
      # errors can be transferred before we freak out.
      throw :fatal_errors_encountered if target_routine.errors? && fail_if_errors
    end

  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
lev-10.1.0 lib/lev/error_transferer.rb
lev-10.0.0 lib/lev/error_transferer.rb
lev-9.0.4 lib/lev/error_transferer.rb
lev-9.0.3 lib/lev/error_transferer.rb
lev-9.0.2 lib/lev/error_transferer.rb
lev-9.0.1 lib/lev/error_transferer.rb
lev-9.0.0 lib/lev/error_transferer.rb
lev-8.1.0 lib/lev/error_transferer.rb
lev-8.0.0 lib/lev/error_transferer.rb
lev-7.1.0 lib/lev/error_transferer.rb
lev-7.0.3 lib/lev/error_transferer.rb
lev-7.0.2 lib/lev/error_transferer.rb
lev-7.0.1 lib/lev/error_transferer.rb
lev-7.0.0 lib/lev/error_transferer.rb
lev-6.0.0 lib/lev/error_transferer.rb