Module: Roda::Component::Form::Validations
- Included in:
- Roda::Component::Form
- Defined in:
- lib/roda/component/form/validations.rb
Overview
Provides a base implementation for extensible validation routines. Scrivener::Validations currently only provides the following assertions:
- assert
- assert_present
- assert_format
- assert_numeric
- assert_url
- assert_email
- assert_member
- assert_length
- assert_decimal
- assert_equal
The core tenets that Scrivener::Validations advocates can be summed up in a few bullet points:
- Validations are much simpler and better done using composition rather than macros.
- Error messages should be kept separate and possibly in the view or presenter layer.
- It should be easy to write your own validation routine.
Other validations are simply added on a per-model or per-project basis.
Instance Method Summary collapse
-
#errors ⇒ Object
Hash of errors for each attribute in this model.
-
#valid? ⇒ Boolean
Check if the current model state is valid.
-
#validate ⇒ Object
Base validate implementation.
Instance Method Details
#errors ⇒ Object
Hash of errors for each attribute in this model.
82 83 84 |
# File 'lib/roda/component/form/validations.rb', line 82 def errors @errors ||= Hash.new { |hash, key| hash[key] = [] } end |
#valid? ⇒ Boolean
71 72 73 74 75 |
# File 'lib/roda/component/form/validations.rb', line 71 def valid? errors.clear validate errors.empty? end |
#validate ⇒ Object
Base validate implementation. Override this method in subclasses.
78 79 |
# File 'lib/roda/component/form/validations.rb', line 78 def validate end |