Sha256: 7e7f921baf04772c2406a7a6c09f05fe5b7dd68dcdbac44da67c0c014453d7ac

Contents?: true

Size: 825 Bytes

Versions: 3

Compression:

Stored size: 825 Bytes

Contents

module Slugged
  module SlugHistory
    extend ActiveSupport::Concern
    
    included do
      after_save :record_slug_changes
      after_destroy :remove_slug_history!
    end

    def previous_slugs
      Slugged.previous_slugs_for(self)
    end
    
    def remove_slug_history!
      Slugged.remove_slug_history_for(self)
    end
    
    protected
    
    def record_slug_changes
      slug_column = self.cached_slug_column
      return unless send(:"#{slug_column}_changed?")
      value = send(:"#{slug_column}_was")
      Slugged.record_slug(self, value) if value.present?
    end
    
    module ClassMethods
      
      def find_using_slug_history(slug, options = {})
        id = Slugged.last_known_slug_id(self, slug)
        id.present? ? find_by_id(id, options) : nil
      end
      
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slugged-1.1.0 lib/slugged/slug_history.rb
slugged-1.0.1 lib/slugged/slug_history.rb
slugged-1.0.0 lib/slugged/slug_history.rb