Module: Bronze::Entities::PrimaryKeys::Uuid::ClassMethods

Defined in:
lib/bronze/entities/primary_keys/uuid.rb

Overview

Class methods to define when including PrimaryKeys::Uuid in a class.

Instance Method Summary collapse

Instance Method Details

#define_primary_key(attribute_name) ⇒ Attributes::Metadata

Defines a UUID primary key with the specified name.

Examples:

Defining a Primary Key

class Book
  include Bronze::Entities::Attributes
  include Bronze::Entities::PrimaryKey::Uuid

  define_primary_key :id
end # class

book = Book.new
book.id
#=> '19eeac71-2b8b-439a-8f5d-cb63f26e4ddf'

Book.new.id
#=> '4c08d721-8aa2-4ff9-942f-852b5c33bcc9'

Parameters:

  • attribute_name (Symbol, String)

    The name of the primary key.

Returns:



39
40
41
# File 'lib/bronze/entities/primary_keys/uuid.rb', line 39

def define_primary_key(attribute_name)
  super(attribute_name, String, default: -> { SecureRandom.uuid })
end