Class: Evnt::Validator

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

Overview

Validator is a class used to validates params and attributes automatically.

Constant Summary collapse

TYPES =
i[boolean string integer symbol float hash array
date datetime time].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, options) ⇒ Validator

The constructor is used to initialize a new validator.

Attributes

  • value - The value that should be validated.

  • options - The list of options for the validation.

Options

  • presence - Boolean value used to not accept nil values.

  • type - Symbol or String value used to set the type of the value.

  • custom_options - Other options that can change for every type.



29
30
31
32
33
34
35
36
37
38
# File 'lib/evnt/validator.rb', line 29

def initialize(value, options)
  @value = value

  @_options = options
  @_result = true

  _validates_presence if @_result
  _validates_type if @_result
  _validates_custom if @_result
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/evnt/validator.rb', line 10

def value
  @value
end

Instance Method Details

#passed?Boolean

This function tells if the validation is passed or not.

Returns:

  • (Boolean)


43
44
45
# File 'lib/evnt/validator.rb', line 43

def passed?
  @_result
end