module UuidProperties

Constants

UUID_PATTERN
VERSION

Public Class Methods

included(klass) click to toggle source
# File lib/uuid_properties.rb, line 8
def self.included(klass)
  klass.extend(ClassMethods)
  klass.before_validation :generate_uuid
  klass.validates_presence_of :uuid
end

Public Instance Methods

generate_uuid() click to toggle source

The underlying Postgres tables themselves will generate UUIDs by default, but ActiveRecord in general doesn't play nicely with default databases values so we set UUIDs in our models first.

# File lib/uuid_properties.rb, line 17
def generate_uuid
  self.uuid ||= SecureRandom.uuid
end