Module: DestinationErrors

Defined in:
lib/destination_errors.rb,
lib/destination_errors/version.rb,
lib/destination_errors/unique_errors.rb,
lib/destination_errors/active_model_integration.rb

Overview

There are three steps to implementing this module in a class:

Setup 1: include DestinationErrors and set error_surfaces

  include DestinationErrors
  # Usage: set explicitly in each class
  #        individual error surfaces can be nil, it's safe.
  has_error_surfaces [nil, :lead, :user]

  # a simple default with only one surface, nil, where the errors
  # accumulate on the object including this module would be:
  #   has_error_surfaces [nil]

Setup 2: (optional)

  def initialize
    # choose one of the surfaces to aggregate errors onto, with nil indicating self.
    @surface_errors_on = nil
  end

Setup 3: call move_all_errors_to_destination after errors may exist on the error_surfaces

  def finalize
    move_all_errors_to_destination
    self # if you want chainability return self
  end

Defined Under Namespace

Modules: ActiveModelIntegration, ClassMethods, Initializer, UniqueErrors

Constant Summary collapse

VERSION =
"0.0.6"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/destination_errors.rb', line 36

def self.included(base)
  base.prepend(Initializer)
  base.extend(ClassMethods)
  base.include(DestinationErrors::ActiveModelIntegration)
  base.include(DestinationErrors::UniqueErrors)
  base.class_eval do
    attr_accessor :errors_finalized
    attr_accessor :surface_errors_on
    class_attribute :error_surfaces
  end
end

Instance Method Details

#error_surfaces_clean?Boolean

Checks to see if any errors have been registered on any of the error surfaces but:

1. does not re-run validations
2. does not add or move errors

returns true if any errors are found on any surface or false otherwise

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
# File 'lib/destination_errors.rb', line 59

def error_surfaces_clean?
  return false if self.errors.any?
  self.class.error_surfaces.compact.each do |surface|
    return false if errors_on_surface?(surface)
  end
  return false if custom_error_destination_has_errors?
  return true
end