Class: Valcro::ErrorList

Inherits:
Object
  • Object
show all
Defined in:
lib/valcro/error_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeErrorList

Returns a new instance of ErrorList.



4
5
6
# File 'lib/valcro/error_list.rb', line 4

def initialize
  @errors = []
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



3
4
5
# File 'lib/valcro/error_list.rb', line 3

def errors
  @errors
end

Instance Method Details

#<<(error) ⇒ Object



8
9
10
# File 'lib/valcro/error_list.rb', line 8

def <<(error)
  @errors << error
end

#[](prop) ⇒ Object



16
17
18
# File 'lib/valcro/error_list.rb', line 16

def [](prop)
  @errors.select { |error| error.property == prop }.map(&:message) || []
end

#add(prop, message) ⇒ Object



12
13
14
# File 'lib/valcro/error_list.rb', line 12

def add(prop, message)
  @errors << Valcro::Error.new(prop, message)
end

#any?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/valcro/error_list.rb', line 32

def any?
  @errors.any?
end

#clear!Object



20
21
22
# File 'lib/valcro/error_list.rb', line 20

def clear!
  @errors = []
end

#full_messagesObject



24
25
26
# File 'lib/valcro/error_list.rb', line 24

def full_messages
  @errors.map(&:to_s)
end

#to_sObject



28
29
30
# File 'lib/valcro/error_list.rb', line 28

def to_s
  full_messages.join(' ')
end