Module: TooShort::ARBaseExtensions

Defined in:
lib/ar_base_extensions.rb

Instance Method Summary collapse

Instance Method Details

#has_a_short_url(options = {}) ⇒ Object

To be included in your model, i.e class Post

has_a_short_url

end

Takes the following options:

host: short URL host to use (alternatively to be defined in an initializer file)
scope: the scope for this model, necessary when short URLs are used in multiple models


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ar_base_extensions.rb', line 14

def has_a_short_url(options={})
  short_url_options = TooShort.options.merge(options)
  short_url_options.symbolize_keys!
  class_attribute :short_url_options
  self.short_url_options = short_url_options
  
  TooShort.register_class(self.to_s, short_url_options[:scope])
  
  class_eval do
    include InstanceMethods
  end
end