22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/ardb/has_slug.rb', line 22
def has_slug(options = nil)
options ||= {}
raise(ArgumentError, "a source must be provided") unless options[:source]
@ardb_has_slug_config.merge!({
:attribute => options[:attribute] || DEFAULT_ATTRIBUTE,
: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(self.ardb_has_slug_config[:attribute], :on => :update)
validates_uniqueness_of(self.ardb_has_slug_config[:attribute], {
:case_sensitive => true,
:scope => options[:unique_scope]
})
after_create :ardb_has_slug_generate_slug
after_update :ardb_has_slug_generate_slug
end
|