Class: ActiveModel::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/active_model/errors_ext.rb

Constant Summary collapse

@@error_class =
ActiveModel::Error

Instance Method Summary collapse

Instance Method Details

#[](attribute) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/active_model/errors_ext.rb', line 13

def [](attribute)
  if errors = get(attribute.to_sym)
    errors
  else
    set(attribute.to_sym, AttributeErrors.new(self, attribute.to_sym))
  end
end

#add(attribute, message = nil, options = {}) ⇒ Object



21
22
23
# File 'lib/active_model/errors_ext.rb', line 21

def add(attribute, message = nil, options = {})
  self[attribute].add(message, options)
end

#generate_message(attribute, type = :invalid, options = {}) ⇒ Object



25
26
27
28
# File 'lib/active_model/errors_ext.rb', line 25

def generate_message(attribute, type = :invalid, options = {})
  options.update(:model => @base, :attribute => attribute)
  error_class.new(options.delete(:default) || type, options)
end