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.
122 123 124 |
# File 'lib/veto/validator.rb', line 122 def clear_errors @errors = nil end |
#entity ⇒ Object
Returns validating entity instance
110 111 112 |
# File 'lib/veto/validator.rb', line 110 def entity @entity end |
#errors ⇒ Veto::Errors
117 118 119 |
# File 'lib/veto/validator.rb', line 117 def errors @errors ||= ::Veto::Errors.new end |
#initialize(entity) ⇒ Object
Initializes validator
104 105 106 |
# File 'lib/veto/validator.rb', line 104 def initialize entity @entity = entity end |
#valid? ⇒ Boolean
129 130 131 132 |
# File 'lib/veto/validator.rb', line 129 def valid? execute errors.empty? end |
#validate! ⇒ Object
Raises exception if entity is invalid
142 143 144 |
# File 'lib/veto/validator.rb', line 142 def validate! raise(::Veto::InvalidEntity, errors.) unless valid? end |