Module: Sluggable::InstanceMethods

Defined in:
lib/sluggable.rb

Instance Method Summary collapse

Instance Method Details

#conditions_for(column, include = true) ⇒ Object



34
35
36
37
# File 'lib/sluggable.rb', line 34

def conditions_for(column, include = true)
  operator = include ? '=' : '!='
  ["#{column} #{operator} ?", self[column]] unless self[column].blank?
end

#slug_conditionsObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/sluggable.rb', line 39

def slug_conditions
  condition_parts = [conditions_for(:id, false)]
  condition_parts += slug_scope.map {|c| conditions_for(c) }
  condition_parts.compact!
  
  condition_string     = condition_parts.map {|p| p[0] }.join(' AND ')
  condition_parameters = condition_parts.map {|p| p[1] }

  condition_parts.empty? ? {} : {:conditions => [condition_string, *condition_parameters]}
end