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

Defined in:
lib/mls.rb

Instance Method Summary collapse

Instance Method Details

#find(*ids) ⇒ Object



101
102
103
104
105
106
107
108
109
110
# File 'lib/mls.rb', line 101

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) }
  
  if ids.first.include?("@")
    self.filter(email_addresses: {address: ids.first}).first
  else
    find_by_slug!(ids.first)
  end
end

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



93
94
95
96
97
98
99
# File 'lib/mls.rb', line 93

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