Class: Kharon::CoolValidator

Inherits:
Validator show all
Defined in:
lib/cool_validator.rb

Overview

This validator is really cooler than the other one. It will help you validate datas without raising exception, if you don't want to.

Instance Attribute Summary collapse

Attributes inherited from Validator

#datas, #filtered

Instance Method Summary collapse

Methods inherited from Validator

#any, #array, #boolean, #date, #datetime, #hash, #integer, #numeric, #ssid, #text

Constructor Details

#initialize(datas) ⇒ CoolValidator

Constructor of the classe, receiving the datas to validate and filter.

Examples:

create a new instance of validator.

@validator = Kharon::CoolValidator.new({key: "value"})

Parameters:

  • datas (Hash)

    the datas to validate in the validator.



16
17
18
19
# File 'lib/cool_validator.rb', line 16

def initialize(datas)
  super(datas)
  @errors = Array.new
end

Instance Attribute Details

#errorsObject (readonly)

Returns an array of strings, each string representing an error occured while validating the hash.

Returns:

  • an array of strings, each string representing an error occured while validating the hash.



# File 'lib/cool_validator.rb', line 8


Instance Method Details

#has_errors?Boolean

Fancy method to see if the validator have seen an error in the given hash.

Returns:

  • (Boolean)


22
23
24
# File 'lib/cool_validator.rb', line 22

def has_errors?
  return (@errors.empty? ? false : true)
end