Class: ActiveRecord::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/validations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, attribute, type = nil, options = {}) ⇒ Error

Returns a new instance of Error.



21
22
23
24
25
26
27
# File 'lib/active_record/validations.rb', line 21

def initialize(base, attribute, type = nil, options = {})
  self.base      = base
  self.attribute = attribute
  self.type      = type || :invalid
  self.options   = options
  self.message   = options.delete(:message) || self.type
end

Instance Attribute Details

#attributeObject

Returns the value of attribute attribute.



19
20
21
# File 'lib/active_record/validations.rb', line 19

def attribute
  @attribute
end

#baseObject

Returns the value of attribute base.



19
20
21
# File 'lib/active_record/validations.rb', line 19

def base
  @base
end

#messageObject Also known as: to_s

Returns the value of attribute message.



19
20
21
# File 'lib/active_record/validations.rb', line 19

def message
  @message
end

#optionsObject

Returns the value of attribute options.



19
20
21
# File 'lib/active_record/validations.rb', line 19

def options
  @options
end

#typeObject

Returns the value of attribute type.



19
20
21
# File 'lib/active_record/validations.rb', line 19

def type
  @type
end

Instance Method Details

#full_messageObject



35
36
37
# File 'lib/active_record/validations.rb', line 35

def full_message
  attribute.to_s == 'base' ? message : generate_full_message(default_options)
end

#valueObject



41
42
43
# File 'lib/active_record/validations.rb', line 41

def value
  @base.respond_to?(attribute) ? @base.send(attribute) : nil
end