Module: Veto::Validator
- Defined in:
- lib/veto/validator.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#clear_errors ⇒ Object
Sets errors to nil.
-
#entity ⇒ Object
Returns validating entity instance.
- #errors ⇒ Veto::Errors
-
#initialize(entity) ⇒ Object
Initializes validator.
- #valid? ⇒ Boolean
-
#validate! ⇒ Object
Raises exception if entity is invalid.
Class Method Details
.included(base) ⇒ Object
7 8 9 |
# File 'lib/veto/validator.rb', line 7 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#clear_errors ⇒ Object
Sets errors to nil.
101 102 103 |
# File 'lib/veto/validator.rb', line 101 def clear_errors @errors = nil end |
#entity ⇒ Object
Returns validating entity instance
89 90 91 |
# File 'lib/veto/validator.rb', line 89 def entity @entity end |
#errors ⇒ Veto::Errors
96 97 98 |
# File 'lib/veto/validator.rb', line 96 def errors @errors ||= ::Veto::Errors.new end |
#initialize(entity) ⇒ Object
Initializes validator
83 84 85 |
# File 'lib/veto/validator.rb', line 83 def initialize entity @entity = entity end |
#valid? ⇒ Boolean
108 109 110 111 |
# File 'lib/veto/validator.rb', line 108 def valid? execute errors.empty? end |
#validate! ⇒ Object
Raises exception if entity is invalid
121 122 123 |
# File 'lib/veto/validator.rb', line 121 def validate! raise(::Veto::InvalidEntity, errors.) unless valid? end |