# File lib/lucky_sneaks/acts_as_url.rb, line 29
29:       def acts_as_url(attribute, options = {})
30:         cattr_accessor :attribute_to_urlify
31:         cattr_accessor :scope_for_url
32:         cattr_accessor :url_attribute # The attribute on the DB
33:         cattr_accessor :only_when_blank
34:         cattr_accessor :duplicate_count_separator
35: 
36:         if options[:sync_url]
37:           before_validation(:ensure_unique_url)
38:         else
39:           if defined?(ActiveModel::Callbacks)
40:             before_validation(:ensure_unique_url, :on => :create)
41:           else
42:             before_validation_on_create(:ensure_unique_url)
43:           end
44:         end
45: 
46:         self.attribute_to_urlify = attribute
47:         self.scope_for_url = options[:scope]
48:         self.url_attribute = options[:url_attribute] || "url"
49:         self.only_when_blank = options[:only_when_blank] || false
50:         self.duplicate_count_separator = options[:duplicate_count_separator] || "-"
51: 
52:         class_eval "def \#{url_attribute}\nif !new_record? && errors[attribute_to_urlify].present?\nself.class.find(id).send(url_attribute)\nelse\nread_attribute(url_attribute)\nend\nend\n"
53:       end