Class: IknowParams::Serializer::UUID

Inherits:
String show all
Defined in:
lib/iknow_params/serializer.rb

Instance Attribute Summary

Attributes inherited from IknowParams::Serializer

#clazz

Instance Method Summary collapse

Methods inherited from String

#initialize

Methods inherited from IknowParams::Serializer

#dump, for, for!, #initialize, json_value?, #matches_type!, singleton

Constructor Details

This class inherits a constructor from IknowParams::Serializer::String

Instance Method Details

#load(str) ⇒ Object



238
239
240
241
242
243
244
245
246
# File 'lib/iknow_params/serializer.rb', line 238

def load(str)
  matches_type!(str, err: LoadError)

  # UUIDs in Ruby are typically represented as lower case strings,
  # for example, as returned by SecureRandom.uuid. To avoid surprises,
  # and ensure that two equivalent UUIDs are equal to each other, we
  # canonicalize any provided strings to lower case.
  super.downcase
end

#matches_type?(str) ⇒ Boolean

Returns:



248
249
250
# File 'lib/iknow_params/serializer.rb', line 248

def matches_type?(str)
  super && /[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}/i.match?(str)
end