Class: Cuprum::Rails::MapErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/cuprum/rails/map_errors.rb

Overview

Maps errors from a validated Rails model to a Stannum::Errors object.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceMapErrors

Returns a memoized instance of the class.

Returns:

  • (MapErrors)

    a memoized instance of the class.



11
12
13
# File 'lib/cuprum/rails/map_errors.rb', line 11

def self.instance
  @instance ||= new
end

Instance Method Details

#call(native_errors:) ⇒ Stannum::Errors

Maps an ActiveModel::Errors object to a Stannum::Errors object.

Parameters:

  • native_errors (ActiveModel::Errors)

    The Rails error object.

Returns:

  • (Stannum::Errors)

    the generated errors object.



20
21
22
23
24
25
26
27
# File 'lib/cuprum/rails/map_errors.rb', line 20

def call(native_errors:)
  unless native_errors.is_a?(ActiveModel::Errors)
    raise ArgumentError,
      'native_errors must be an instance of ActiveModel::Errors'
  end

  map_errors(native_errors: native_errors)
end