Class: ActiveModel::Error

Inherits:
Object show all
Defined in:
lib/reactive_record/active_record/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_msgs = {}) ⇒ Error

Returns a new instance of Error.



6
7
8
9
# File 'lib/reactive_record/active_record/error.rb', line 6

def initialize(initial_msgs = {})
  @messages = Hash.new { |h, k| h[k] = [] }
  initial_msgs.each { |attr, msgs| @messages[attr] = msgs.uniq }
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



4
5
6
# File 'lib/reactive_record/active_record/error.rb', line 4

def messages
  @messages
end

Instance Method Details

#[](attribute) ⇒ Object



11
12
13
# File 'lib/reactive_record/active_record/error.rb', line 11

def [](attribute)
  messages[attribute]
end

#add(attribute, message = :invalid, _options = {}) ⇒ Object



27
28
29
# File 'lib/reactive_record/active_record/error.rb', line 27

def add(attribute, message = :invalid, _options = {})
  @messages[attribute] << message unless @messages[attribute].include? message
end

#clearObject



23
24
25
# File 'lib/reactive_record/active_record/error.rb', line 23

def clear
  @messages.clear
end

#delete(attribute) ⇒ Object



15
16
17
# File 'lib/reactive_record/active_record/error.rb', line 15

def delete(attribute)
  messages.delete(attribute)
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  messages.empty?
end