class Ciesta::Validator
Validatior class for form
@attr_reader [Dry::Validation::Schema] schema Schema for validation @attr_reader [Hash] errors Array with errors
Attributes
errors[R]
schema[R]
Public Class Methods
new()
click to toggle source
Constructor
# File lib/ciesta/validator.rb, line 11 def initialize @errors = [] end
Public Instance Methods
use(&block)
click to toggle source
Set schema for validation
@api private @param [Block] block Block wich returns the schema
# File lib/ciesta/validator.rb, line 19 def use(&block) @schema = Dry::Validation.Params(&block) end
valid?(attributes)
click to toggle source
Checks if schema is valid
@param [Hash<Symbol, any>] attributes Attributes to check
@api private @return [Boolean]
# File lib/ciesta/validator.rb, line 29 def valid?(attributes) return true if schema.nil? @errors = schema.call(attributes).errors errors.empty? end