Class: Apes::Validators::UuidValidator

Inherits:
BaseValidator
  • Object
show all
Defined in:
lib/apes/validators.rb

Overview

Validates UUIDs (version 4).

Constant Summary

VALID_REGEX =

The pattern to recognized a valid UUID version 4.

/\A[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\z/i

Instance Method Summary (collapse)

Methods inherited from BaseValidator

#validate_each

Constructor Details

- (Apes::Validators::UuidValidator) initialize(options)

Creates a new validator.

Parameters:

  • options (Hash)

    The options for the validations.



72
73
74
# File 'lib/apes/validators.rb', line 72

def initialize(options)
  super(options.reverse_merge(default_message: "must be a valid UUID"))
end

Instance Method Details

- (Boolean) check_valid?(value)

Checks if the value is valid for this validator.

Parameters:

  • value (Object)

    The value to validate.

Returns:

  • (Boolean)

    true if the value is valid, false otherwise.



80
81
82
# File 'lib/apes/validators.rb', line 80

def check_valid?(value)
  value.blank? || value =~ VALID_REGEX
end