Class: ROM::Model::Form::ErrorProxy Private

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/rom/rails/model/form/error_proxy.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Proxy for form errors

This simple proxy forwards most messages to a wrapped ActiveModel::Errors object

Instance Method Summary collapse

Constructor Details

#initializeErrorProxy

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ErrorProxy.



13
14
15
# File 'lib/rom/rails/model/form/error_proxy.rb', line 13

def initialize
  super ActiveModel::Errors.new([])
end

Instance Method Details

#set(error) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

update the current errors

When the argument is an AM Error object, or our wrapper around one, replace the wrapped object. Otherwise, add an error to the current messages

Parameters:

  • error (ActiveModel::Errors, ROM::Model::ValidatonError, object)

Returns:

  • (self)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rom/rails/model/form/error_proxy.rb', line 28

def set(error)
  case error
  when ActiveModel::Errors
    __setobj__ error
  when ROM::Model::ValidationError
    __setobj__ error.errors
  when nil
    # do nothing
  else
    add(:base, "a database error prevented saving this form")
  end

  self
end

#success?Boolean

Has the command succeeded?

Returns:

  • (Boolean)


48
49
50
# File 'lib/rom/rails/model/form/error_proxy.rb', line 48

def success?
  !present?
end