Class: Notifications::UuidValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/notifications/client/uuid_validator.rb

Constant Summary collapse

HEX =
/[0-9a-f]/
REGEX =
/^#{HEX}{8}-#{HEX}{4}-#{HEX}{4}-#{HEX}{4}-#{HEX}{12}$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid) ⇒ UuidValidator

Returns a new instance of UuidValidator.



8
9
10
# File 'lib/notifications/client/uuid_validator.rb', line 8

def initialize(uuid)
  self.uuid = uuid
end

Instance Attribute Details

#uuidObject

Returns the value of attribute uuid.



6
7
8
# File 'lib/notifications/client/uuid_validator.rb', line 6

def uuid
  @uuid
end

Class Method Details

.validate!(uuid, contextual_message = nil) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
# File 'lib/notifications/client/uuid_validator.rb', line 16

def self.validate!(uuid, contextual_message = nil)
  return if new(uuid).valid?

  message = "#{uuid.inspect} is not a valid uuid"
  message += "\n#{contextual_message}" if contextual_message

  raise ArgumentError, message
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/notifications/client/uuid_validator.rb', line 12

def valid?
  !!(uuid && uuid.match(REGEX))
end