Class: Validation::Validator
- Inherits:
-
Object
- Object
- Validation::Validator
- Includes:
- Rules
- Defined in:
- lib/validation/validator.rb
Overview
Validator is a simple ruby validation class. You don’t use it directly inside your classes like just about every other ruby validation class out there. I chose to implement it in this way so I didn’t automatically pollute the namespace of the objects I wanted to validate.
This also solves the problem of validating forms very nicely. Frequently you will have a form that represents many different data objects in your system, and you can pre-validate everything before doing any saving.
Instance Method Summary collapse
-
#initialize(obj) ⇒ Validator
constructor
A new instance of Validator.
Methods included from Rules
#errors, #rule, #rules, #valid?
Constructor Details
#initialize(obj) ⇒ Validator
Returns a new instance of Validator.
112 113 114 115 |
# File 'lib/validation/validator.rb', line 112 def initialize(obj) @rules = self.class.rules if self.class.is_a?(Validation::Rules) @obj = obj end |