Module: Ext::Uuid

Included in:
Event, Member, Show, Ticket
Defined in:
app/models/ext.rb

Overview

Includers will have a uuid generated for them before_create Method self.multi_find can be used to find by either id or uuid

Requires a :uuid column on the including class

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

PREFIX =

Required to prevent Ruby from parsing uuid’s with leading digits into a primary key id

"art-"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



13
14
15
16
17
18
# File 'app/models/ext.rb', line 13

def self.included(base)
  base.class_eval do
    before_create :set_uuid
  end
  base.extend ClassMethods
end

.uuidObject



33
34
35
# File 'app/models/ext.rb', line 33

def self.uuid
  PREFIX + SecureRandom.uuid
end

Instance Method Details

#set_uuidObject



27
28
29
30
31
# File 'app/models/ext.rb', line 27

def set_uuid
  if self.uuid.nil?
    self.uuid = PREFIX + SecureRandom.uuid
  end
end