Class: Validation::Rule::DiasporaId
- Inherits:
-
Object
- Object
- Validation::Rule::DiasporaId
- Defined in:
- lib/diaspora_federation/validators/rules/diaspora_id.rb
Overview
diaspora* ID validation rule
A simple rule to validate the base structure of diaspora* IDs.
Constant Summary collapse
- DIASPORA_ID_MAX_LENGTH =
Maximum length of a full diaspora* ID
255
- DIASPORA_ID_REGEX =
The Regex for a valid diaspora* ID
begin username = "[[:lower:]\\d\\-\\.\\_]+" hostname_part = "[[:lower:]\\d\\-]" hostname = "#{hostname_part}+(?:[.]#{hostname_part}*)*" ipv4 = "(?:[\\d]{1,3}\\.){3}[\\d]{1,3}" ipv6 = "\\[(?:[[:xdigit:]]{0,4}:){0,7}[[:xdigit:]]{1,4}\\]" ip_addr = "(?:#{ipv4}|#{ipv6})" domain = "(?:#{hostname}|#{ip_addr})" port = "(?::[\\d]+)?" "#{username}\\@#{domain}#{port}" end
- DIASPORA_ID =
The Regex for validating a full diaspora* ID
/\A#{DIASPORA_ID_REGEX}\z/u.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 diaspora* ID.
Instance Method Details
#error_key ⇒ Symbol
The error key for this rule
31 32 33 |
# File 'lib/diaspora_federation/validators/rules/diaspora_id.rb', line 31 def error_key :diaspora_id end |
#params ⇒ Hash
This rule has no params.
45 46 47 |
# File 'lib/diaspora_federation/validators/rules/diaspora_id.rb', line 45 def params {} end |
#valid_value?(value) ⇒ Boolean
Determines if value is a valid diaspora* ID
36 37 38 39 40 41 |
# File 'lib/diaspora_federation/validators/rules/diaspora_id.rb', line 36 def valid_value?(value) return false unless value.is_a?(String) return false if value.length > DIASPORA_ID_MAX_LENGTH value =~ DIASPORA_ID end |