Exception: MuchRails::Records::DestructionInvalid

Inherits:
StandardError
  • Object
show all
Defined in:
lib/much-rails/records/validate_destroy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record = nil, field_name: :base) ⇒ DestructionInvalid

Returns a new instance of DestructionInvalid.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/much-rails/records/validate_destroy.rb', line 70

def initialize(record = nil, field_name: :base)
  super(record&.destruction_error_messages.to_a.join("\n"))

  @record = record

  messages = record&.destruction_error_messages.to_a
  @errors =
    if messages.any?
      { field_name.to_sym => messages }
    else
      {}
    end

  @error_full_messages =
    if field_name == :base
      messages
    else
      messages.map do |m|
        ActiveModel::Error.new(@record, field_name, m).full_message
      end
    end
end

Instance Attribute Details

#error_full_messagesObject (readonly)

Returns the value of attribute error_full_messages.



68
69
70
# File 'lib/much-rails/records/validate_destroy.rb', line 68

def error_full_messages
  @error_full_messages
end

#errorsObject (readonly)

Returns the value of attribute errors.



68
69
70
# File 'lib/much-rails/records/validate_destroy.rb', line 68

def errors
  @errors
end

#recordObject (readonly)

Returns the value of attribute record.



68
69
70
# File 'lib/much-rails/records/validate_destroy.rb', line 68

def record
  @record
end