Module: Wedge::Plugins::Form::Validations
- Included in:
- Wedge::Plugins::Form
- Defined in:
- lib/wedge/plugins/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.
Class Method Summary collapse
Instance Method Summary collapse
- #client? ⇒ Boolean (also: #client)
-
#errors ⇒ Object
Hash of errors for each attribute in this model.
- #server?(&block) ⇒ Boolean (also: #server)
-
#valid? ⇒ Boolean
Check if the current model state is valid.
-
#validate ⇒ Object
Base validate implementation.
Class Method Details
.client? ⇒ Boolean
68 69 70 |
# File 'lib/wedge/plugins/validations.rb', line 68 def self.client? RUBY_ENGINE == 'opal' end |
.server?(&block) ⇒ Boolean
63 64 65 |
# File 'lib/wedge/plugins/validations.rb', line 63 def self.server? &block RUBY_ENGINE == 'ruby' end |
Instance Method Details
#client? ⇒ Boolean Also known as: client
58 59 60 |
# File 'lib/wedge/plugins/validations.rb', line 58 def client? RUBY_ENGINE == 'opal' end |
#errors ⇒ Object
Hash of errors for each attribute in this model.
101 102 103 |
# File 'lib/wedge/plugins/validations.rb', line 101 def errors @errors ||= Hash.new { |hash, key| hash[key] = [] } end |
#server?(&block) ⇒ Boolean Also known as: server
53 54 55 |
# File 'lib/wedge/plugins/validations.rb', line 53 def server? &block RUBY_ENGINE == 'ruby' end |
#valid? ⇒ Boolean
90 91 92 93 94 |
# File 'lib/wedge/plugins/validations.rb', line 90 def valid? errors.clear validate errors.empty? end |
#validate ⇒ Object
Base validate implementation. Override this method in subclasses.
97 98 |
# File 'lib/wedge/plugins/validations.rb', line 97 def validate end |