Module: Lite::Uxid::Record::Obfuscateid

Defined in:
lib/lite/uxid/record/obfuscateid.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/lite/uxid/record/obfuscateid.rb', line 8

def self.included(base)
  base.extend ClassMethods
  base.class_eval do
    after_commit :callback_generate_uxid!,
                 if: proc { respond_to?(:uxid) && !uxid? },
                 on: :create
  end
end

Instance Method Details

#id_to_uxidObject



33
34
35
36
37
# File 'lib/lite/uxid/record/obfuscateid.rb', line 33

def id_to_uxid
  return unless respond_to?(:uxid)

  Lite::Uxid::Reversible::Obfuscateid.encode(id)
end

#uxid_to_idObject



39
40
41
42
43
# File 'lib/lite/uxid/record/obfuscateid.rb', line 39

def uxid_to_id
  return unless respond_to?(:uxid)

  Lite::Uxid::Reversible::Obfuscateid.decode(uxid)
end