Module: Lite::Uxid::Record::Hashid
- Defined in:
- lib/lite/uxid/record/hashid.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/hashid.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_uxid ⇒ Object
33 34 35 36 37 |
# File 'lib/lite/uxid/record/hashid.rb', line 33 def id_to_uxid return unless respond_to?(:uxid) Lite::Uxid::Reversible::Hashid.encode(id, prefix: uxid_prefix) end |
#uxid_prefix ⇒ Object
45 46 47 48 |
# File 'lib/lite/uxid/record/hashid.rb', line 45 def uxid_prefix # Define in your class to enable prefixing uxid. # eg: "sub_" or "user_" end |
#uxid_to_id ⇒ Object
39 40 41 42 43 |
# File 'lib/lite/uxid/record/hashid.rb', line 39 def uxid_to_id return unless respond_to?(:uxid) Lite::Uxid::Reversible::Hashid.decode(uxid, prefix: uxid_prefix) end |