Class: ExternalErrors::ExternalErrorStore

Inherits:
Array
  • Object
show all
Defined in:
lib/external_errors.rb

Overview

Add errors from an external sources (/non-validators) to the model

class SomeModel
  include ActiveModel::Model
  include ExternalErrors
end

some_instance = SomeModel.new
some_instance.valid?
#=> true

some_instance.external_errors << 'some external error'
some_instance.valid?
#=> false

Instance Method Summary collapse

Constructor Details

#initialize(error_added_cb) ⇒ ExternalErrorStore

Returns a new instance of ExternalErrorStore.



17
18
19
# File 'lib/external_errors.rb', line 17

def initialize(error_added_cb)
  @error_added_cb = error_added_cb
end

Instance Method Details

#<<(error) ⇒ Object



21
22
23
24
# File 'lib/external_errors.rb', line 21

def <<(error)
  super error
  @error_added_cb.call(error)
end