Module: MLS::Slugger::ActiveRecordBaseSluggerExtension::ClassMethods

Defined in:
lib/mls.rb

Instance Method Summary collapse

Instance Method Details

#find(*ids) ⇒ Object



98
99
100
101
102
103
# File 'lib/mls.rb', line 98

def find(*ids)
  friendly = -> (id) { id.respond_to?(:to_i) && id.to_i.to_s != id.to_s }
  return super if ids.size > 1 || !ids.all? { |x| friendly.call(x) }

  find_by_slug!(ids.first)
end

#slug(method, options = {}, &block) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/mls.rb', line 90

def slug(method, options={}, &block)
  options = options.with_indifferent_access
  options[:trigger] ||= :after_save
  self.slugger = { :proc => method || block, :options => options }
  self.send(options[:trigger], :set_slug)
  self.send(:include, Slugger::History) if options[:history]
end