class FriendlyId::TaskRunner
Constants
- OLD_SLUG_DAYS
Attributes
days[RW]
klass[RW]
task_options[RW]
Public Class Methods
new(&block)
click to toggle source
# File lib/friendly_id/active_record2/tasks.rb, line 10 def initialize(&block) self.klass = ENV["MODEL"] self.days = ENV["DAYS"] end
Public Instance Methods
days=(days)
click to toggle source
# File lib/friendly_id/active_record2/tasks.rb, line 19 def days=(days) @days = days.blank? ? OLD_SLUG_DAYS : days.to_i end
delete_old_slugs()
click to toggle source
# File lib/friendly_id/active_record2/tasks.rb, line 47 def delete_old_slugs conditions = ["created_at < ?", DateTime.now - days.days] if klass conditions[0] << " AND sluggable_type = ?" conditions << klass.to_s end Slug.all(:conditions => conditions).select(&:outdated?).map(&:destroy) end
delete_slugs()
click to toggle source
# File lib/friendly_id/active_record2/tasks.rb, line 39 def delete_slugs validate_uses_slugs Slug.destroy_all(["sluggable_type = ?", klass.to_s]) if column = friendly_id_config.cache_column update_all("#{column} = NULL") end end
klass=(klass)
click to toggle source
# File lib/friendly_id/active_record2/tasks.rb, line 23 def klass=(klass) @klass = klass.to_s.classify.constantize unless klass.blank? end
make_slugs() { |record| ... }
click to toggle source
# File lib/friendly_id/active_record2/tasks.rb, line 27 def make_slugs validate_uses_slugs options = {:limit => 100, :include => :slugs, :conditions => "slugs.id IS NULL"}.merge(task_options || {}) while records = find(:all, options) do break if records.size == 0 records.each do |record| record.save! yield(record) if block_given? end end end
method_missing(*args)
click to toggle source
# File lib/friendly_id/active_record2/tasks.rb, line 15 def method_missing(*args) klass.send(*args) end
validate_uses_slugs()
click to toggle source
# File lib/friendly_id/active_record2/tasks.rb, line 56 def validate_uses_slugs unless friendly_id_config.use_slug? raise "Class '%s' doesn't use slugs" % klass.to_s end rescue NoMethodError raise "Class '%s' doesn't use FriendlyId" % klass.to_s end