Class: Ciesta::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/ciesta/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeValidator

Returns a new instance of Validator.



5
6
7
# File 'lib/ciesta/validator.rb', line 5

def initialize
  self.errors = []
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



3
4
5
# File 'lib/ciesta/validator.rb', line 3

def errors
  @errors
end

#schemaObject

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

Returns:

  • (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