Class: Validation::Rule::Guid
- Inherits:
-
Object
- Object
- Validation::Rule::Guid
- 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
-
#error_key ⇒ Symbol
The error key for this rule.
-
#params ⇒ Hash
This rule has no params.
-
#valid_value?(value) ⇒ Boolean
Determines if value is a valid
GUID
.
Instance Method Details
#error_key ⇒ Symbol
The error key for this rule
16 17 18 |
# File 'lib/diaspora_federation/validators/rules/guid.rb', line 16 def error_key :guid end |
#params ⇒ Hash
This rule has no 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
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 |