Module: QuickShort::HasShortId::InstanceMethods

Defined in:
lib/quick_short/has_short_id.rb

Overview

Instance methods for things that has_short_id

Instance Method Summary collapse

Instance Method Details

#short_idString

Get the short id (expects a method named #id to be defined on this class)

Returns:

  • (String)

    the generated short id



25
26
27
28
29
30
31
# File 'lib/quick_short/has_short_id.rb', line 25

def short_id
  if id
    mthd = {}.methods.include?(:key) ? :key : :index
    prefix = QuickShort.short_id_prefixes.send(mthd, self.class)
    "#{prefix}-#{QuickShort::ShortId.encode(id)}"
  end
end