Class: ActiveForm::Errors
- Includes:
- Enumerable
- Defined in:
- lib/active_form/errors.rb
Constant Summary collapse
- @@default_msg =
'A validation error occurred'
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
Instance Method Summary collapse
- #<<(error) ⇒ Object
- #add(msg = @@default_msg, error_code = 'default', params = []) ⇒ Object
- #at(index) ⇒ Object (also: #[])
- #clear ⇒ Object (also: #reset)
- #each(&block) ⇒ Object
- #errors ⇒ Object (also: #all)
- #first ⇒ Object
-
#initialize(element) ⇒ Errors
constructor
A new instance of Errors.
- #length ⇒ Object (also: #size)
- #valid? ⇒ Boolean
Constructor Details
#initialize(element) ⇒ Errors
Returns a new instance of Errors.
27 28 29 |
# File 'lib/active_form/errors.rb', line 27 def initialize(element) @errors, @element = [], element end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
25 26 27 |
# File 'lib/active_form/errors.rb', line 25 def element @element end |
Instance Method Details
#<<(error) ⇒ Object
35 36 37 |
# File 'lib/active_form/errors.rb', line 35 def <<(error) @errors << error if error.kind_of?(ActiveForm::Error) end |
#add(msg = @@default_msg, error_code = 'default', params = []) ⇒ Object
31 32 33 |
# File 'lib/active_form/errors.rb', line 31 def add(msg = @@default_msg, error_code = 'default', params = []) @errors << ActiveForm::Error.new(element, msg, error_code, params) end |
#at(index) ⇒ Object Also known as: []
52 53 54 |
# File 'lib/active_form/errors.rb', line 52 def at(index) errors.at(index) end |
#clear ⇒ Object Also known as: reset
61 62 63 |
# File 'lib/active_form/errors.rb', line 61 def clear @errors.clear end |
#each(&block) ⇒ Object
57 58 59 |
# File 'lib/active_form/errors.rb', line 57 def each(&block) @errors.each { |error| block.call(error) } end |
#errors ⇒ Object Also known as: all
47 48 49 |
# File 'lib/active_form/errors.rb', line 47 def errors @errors ||= [] end |
#first ⇒ Object
43 44 45 |
# File 'lib/active_form/errors.rb', line 43 def first errors.first end |
#length ⇒ Object Also known as: size
66 67 68 |
# File 'lib/active_form/errors.rb', line 66 def length @errors.length end |
#valid? ⇒ Boolean
39 40 41 |
# File 'lib/active_form/errors.rb', line 39 def valid? errors.empty? end |