21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/ardb/has_slug.rb', line 21
def has_slug(options = nil)
options ||= {}
raise(ArgumentError, "a source must be provided") unless options[:source]
attribute = (options[:attribute] || DEFAULT_ATTRIBUTE).to_sym
@ardb_has_slug_configs[attribute].merge!({
:source_proc => options[:source].to_proc,
:preprocessor_proc => (options[:preprocessor] || DEFAULT_PREPROCESSOR).to_proc,
:separator => options[:separator] || DEFAULT_SEPARATOR,
:allow_underscores => !!options[:allow_underscores]
})
validates_presence_of(attribute, :on => :update)
if options[:skip_unique_validation] != true
validates_uniqueness_of(attribute, {
:case_sensitive => true,
:scope => options[:unique_scope]
})
end
after_create :ardb_has_slug_generate_slugs
after_update :ardb_has_slug_generate_slugs
end
|