Module: UrlKeyedObject::ActiveRecord

Defined in:
lib/url_keyed_object/active_record.rb

Defined Under Namespace

Modules: Extensions Classes: Helper

Instance Method Summary collapse

Instance Method Details

#has_url_key(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/url_keyed_object/active_record.rb', line 6

def has_url_key(opts = {})
  url_key_column = opts.has_key?(:column) ? opts[:column] : :url_key
  url_key_length = opts.has_key?(:length) ? opts[:length] : 5

  include UrlKeyedObject::ActiveRecord::Extensions

  attr_protected url_key_column
  before_create :generate_valid_url_key

  @url_key_helper = UrlKeyedObject::ActiveRecord::Helper.new(self, url_key_column, url_key_length)

  define_method("#{url_key_column}=") { |value| logger.warn("Attempt to set ##{url_key_column}!") if self.respond_to?(:logger); nil }
end