Class: ActiveFields::Validators::BaseValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fields/validators/base_validator.rb

Overview

Validates the active_value value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ BaseValidator



9
10
11
12
# File 'lib/active_fields/validators/base_validator.rb', line 9

def initialize(**options)
  @options = options
  @errors = Set.new
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/active_fields/validators/base_validator.rb', line 7

def errors
  @errors
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/active_fields/validators/base_validator.rb', line 7

def options
  @options
end

Instance Method Details

#valid?Boolean

Returns ‘true` if no errors are found, `false` otherwise.



22
23
24
# File 'lib/active_fields/validators/base_validator.rb', line 22

def valid?
  errors.empty?
end

#validate(value) ⇒ Object

Performs the validation and adds errors to the ‘errors` list. Returns `true` if no errors are found, `false` otherwise.



16
17
18
19
# File 'lib/active_fields/validators/base_validator.rb', line 16

def validate(value)
  perform_validation(value)
  valid?
end