Module: ErrorOperationHelper

Overview

typed: ignore Used in Trailblazer based class

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#errorsObject



6
7
8
9
10
# File 'app/my_lib/error_operation_helper.rb', line 6

def errors
  return @skills[OpCons::ERRORS] if @skills[OpCons::ERRORS].is_a?(ActiveModel::Errors)
  @skills[OpCons::ERRORS] = ActiveModel::Errors.new(self)
  @skills[OpCons::ERRORS]
end

#merge_errorsObject

pass another ActiveModel::Errors instance in block

Examples:

merge_errors { another_errors_instance }


16
17
18
19
20
21
22
23
24
# File 'app/my_lib/error_operation_helper.rb', line 16

def merge_errors
  another_errors = yield
  if another_errors.is_a? ActiveModel::Errors
    another_errors.each do |attr, error|
      next if errors.added? attr, error
      errors.add attr, error
    end
  end
end