Module: QuickShort::HasShortId

Defined in:
lib/quick_short/has_short_id.rb

Overview

A mixin for registering a class with short_ids

Defined Under Namespace

Modules: InstanceMethods

Instance Method Summary collapse

Instance Method Details

#has_short_id(prefix) ⇒ Object

Register this class with QuickShort with a certain prefix. With prefix ‘a’, will generate ids like ‘a-lksdjf’

Parameters:

  • prefix (String)
    • The prefix for this class



9
10
11
12
13
14
15
16
17
# File 'lib/quick_short/has_short_id.rb', line 9

def has_short_id(prefix)
  send(:include, InstanceMethods)  
  if QuickShort.short_id_prefixes.has_key?(prefix)
    raise QuickShort::DuplicatePrefix.new(prefix)
  else
    QuickShort.short_id_prefixes[prefix] = self
    self
  end
end