Class: Ciesta::Validator
- Inherits:
-
Object
- Object
- Ciesta::Validator
- Defined in:
- lib/ciesta/validator.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#schema ⇒ Object
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize ⇒ Validator
constructor
A new instance of Validator.
- #use(&block) ⇒ Object
- #valid?(attributes) ⇒ Boolean
Constructor Details
#initialize ⇒ Validator
Returns a new instance of Validator.
5 6 7 |
# File 'lib/ciesta/validator.rb', line 5 def initialize self.errors = [] end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
3 4 5 |
# File 'lib/ciesta/validator.rb', line 3 def errors @errors end |
#schema ⇒ Object
Returns the value of attribute schema.
3 4 5 |
# File 'lib/ciesta/validator.rb', line 3 def schema @schema end |
Instance Method Details
#use(&block) ⇒ Object
9 10 11 |
# File 'lib/ciesta/validator.rb', line 9 def use(&block) self.schema = Dry::Validation.Form(&block) end |
#valid?(attributes) ⇒ Boolean
13 14 15 16 17 18 |
# File 'lib/ciesta/validator.rb', line 13 def valid?(attributes) return true if schema.nil? self.errors = schema.call(attributes).errors errors.empty? end |