Class: Validation::Rule::Guid

Inherits:
Object
  • Object
show all
Defined in:
lib/diaspora_federation/validators/rules/guid.rb

Overview

GUID validation rule

Valid is a String that is at least 16 and at most 255 chars long. It contains only:

  • Letters: a-z

  • Numbers: 0-9

  • Special chars: ‘-’, ‘_’, ‘@’, ‘.’ and ‘:’

Special chars aren’t allowed at the end.

Constant Summary collapse

VALID_CHARS =

Allowed chars to validate a GUID with a regex

"[0-9A-Za-z\\-_@.:]{15,254}[0-9A-Za-z]"

Instance Method Summary collapse

Instance Method Details

#error_keySymbol

The error key for this rule

Returns:

  • (Symbol)

    error key



18
19
20
# File 'lib/diaspora_federation/validators/rules/guid.rb', line 18

def error_key
  :guid
end

#paramsHash

This rule has no params.

Returns:

  • (Hash)

    params



29
30
31
# File 'lib/diaspora_federation/validators/rules/guid.rb', line 29

def params
  {}
end

#valid_value?(value) ⇒ Boolean

Determines if value is a valid GUID

Returns:



23
24
25
# File 'lib/diaspora_federation/validators/rules/guid.rb', line 23

def valid_value?(value)
  value.is_a?(String) && value =~ /\A#{VALID_CHARS}\z/
end