Class: Dsu::Views::Shared::ModelErrors

Inherits:
Error show all
Defined in:
lib/dsu/views/shared/model_errors.rb

Constant Summary

Constants inherited from Message

Dsu::Views::Shared::Message::MESSAGE_TYPES

Instance Method Summary collapse

Methods inherited from Message

#to_s

Methods included from Support::ColorThemable

apply_theme, #prompt_with_options

Constructor Details

#initialize(model:, options: {}) ⇒ ModelErrors

Returns a new instance of ModelErrors.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
# File 'lib/dsu/views/shared/model_errors.rb', line 9

def initialize(model:, options: {})
  raise ArgumentError, 'model is nil' if model.nil?
  raise ArgumentError, "model is the wrong object type: \"#{model}\"" unless model.is_a?(ActiveModel::Model)

  # TODO: I18n.
  header = options[:header] || 'The following ERRORS were encountered; changes could not be saved:'
  super(messages: model.errors.full_messages, header: header, options: options)

  @model = model
end

Instance Method Details

#renderObject



20
21
22
23
24
# File 'lib/dsu/views/shared/model_errors.rb', line 20

def render
  return if model.valid?

  super
end