module ActiveInteractor::Context::Errors
Context
error methods. Because {Errors} is a module classes should include {Errors} rather than inherit from it.
@api private @author Aaron Allen <hello@aaronmallen.me> @since 1.0.3
Public Instance Methods
failure_errors()
click to toggle source
Generic errors generated outside of validation.
@return [ActiveModel::Errors] an instance of `ActiveModel::Errors`
# File lib/active_interactor/context/errors.rb, line 15 def failure_errors @failure_errors ||= ActiveModel::Errors.new(self) end
Private Instance Methods
add_errors(errors)
click to toggle source
# File lib/active_interactor/context/errors.rb, line 21 def add_errors(errors) errors.each do |error| if self.errors.respond_to?(:import) self.errors.import(error) else self.errors.add(error[0], error[1]) end end end
clear_all_errors()
click to toggle source
# File lib/active_interactor/context/errors.rb, line 31 def clear_all_errors errors.clear failure_errors.clear end
handle_errors(errors)
click to toggle source
# File lib/active_interactor/context/errors.rb, line 36 def handle_errors(errors) if errors.is_a?(String) failure_errors.add(:context, errors) else failure_errors.merge!(errors) end end
merge_errors!(other)
click to toggle source
# File lib/active_interactor/context/errors.rb, line 44 def merge_errors!(other) errors.merge!(other.errors) failure_errors.merge!(other.errors) failure_errors.merge!(other.failure_errors) end
resolve_errors()
click to toggle source
# File lib/active_interactor/context/errors.rb, line 50 def resolve_errors all_errors = (failure_errors.uniq + errors.uniq).compact.uniq clear_all_errors add_errors(all_errors) end