Class: Rubee::Validatable::State
- Inherits:
-
Object
- Object
- Rubee::Validatable::State
- Defined in:
- lib/rubee/extensions/validatable.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#valid ⇒ Object
Returns the value of attribute valid.
Instance Method Summary collapse
- #add_error(attribute, hash) ⇒ Object
- #has_errors_for?(attribute) ⇒ Boolean
-
#initialize ⇒ State
constructor
A new instance of State.
Constructor Details
#initialize ⇒ State
Returns a new instance of State.
8 9 10 11 |
# File 'lib/rubee/extensions/validatable.rb', line 8 def initialize @valid = true @errors = {} end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
6 7 8 |
# File 'lib/rubee/extensions/validatable.rb', line 6 def errors @errors end |
#valid ⇒ Object
Returns the value of attribute valid.
6 7 8 |
# File 'lib/rubee/extensions/validatable.rb', line 6 def valid @valid end |
Instance Method Details
#add_error(attribute, hash) ⇒ Object
13 14 15 16 17 |
# File 'lib/rubee/extensions/validatable.rb', line 13 def add_error(attribute, hash) @valid = false @errors[attribute] ||= {} @errors[attribute].merge!(hash) end |
#has_errors_for?(attribute) ⇒ Boolean
19 20 21 |
# File 'lib/rubee/extensions/validatable.rb', line 19 def has_errors_for?(attribute) @errors.key?(attribute) end |