Class: Ciesta::Validator
- Inherits:
-
Object
- Object
- Ciesta::Validator
- Defined in:
- lib/ciesta/validator.rb
Overview
Validatior class for form
Instance Attribute Summary collapse
-
#errors ⇒ Hash
readonly
Array with errors.
Instance Method Summary collapse
-
#initialize ⇒ Validator
constructor
Constructor.
-
#use(&block) ⇒ Object
private
Set schema for validation.
-
#valid?(attributes) ⇒ Boolean
private
Checks if schema is valid.
Constructor Details
#initialize ⇒ Validator
Constructor
11 12 13 |
# File 'lib/ciesta/validator.rb', line 11 def initialize @errors = [] end |
Instance Attribute Details
#errors ⇒ Hash (readonly)
Array with errors
7 8 9 |
# File 'lib/ciesta/validator.rb', line 7 def errors @errors end |
Instance Method Details
#use(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set schema for validation
19 20 21 |
# File 'lib/ciesta/validator.rb', line 19 def use(&block) @schema = Dry::Validation.Params(&block) end |
#valid?(attributes) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if schema is valid
29 30 31 32 33 34 |
# File 'lib/ciesta/validator.rb', line 29 def valid?(attributes) return true if schema.nil? @errors = schema.call(attributes).errors errors.empty? end |