Module: Scrivener::Validations
- Included in:
- Scrivener
- Defined in:
- lib/scrivener/validations.rb
Overview
Provides a base implementation for extensible validation routines. 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.
81 82 83 |
# File 'lib/scrivener/validations.rb', line 81 def errors @errors ||= Hash.new { |hash, key| hash[key] = [] } end |
#valid? ⇒ Boolean
70 71 72 73 74 |
# File 'lib/scrivener/validations.rb', line 70 def valid? errors.clear validate errors.empty? end |
#validate ⇒ Object
Base validate implementation. Override this method in subclasses.
77 78 |
# File 'lib/scrivener/validations.rb', line 77 def validate end |