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]".freeze

Instance Method Summary collapse

Instance Method Details

#error_keySymbol

The error key for this rule

Returns:

  • (Symbol)

    error key



16
17
18
# File 'lib/diaspora_federation/validators/rules/guid.rb', line 16

def error_key
  :guid
end

#paramsHash

This rule has no params.

Returns:

  • (Hash)

    params



27
28
29
# File 'lib/diaspora_federation/validators/rules/guid.rb', line 27

def params
  {}
end

#valid_value?(value) ⇒ Boolean

Determines if value is a valid GUID

Returns:



21
22
23
# File 'lib/diaspora_federation/validators/rules/guid.rb', line 21

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