Sha256: 5d9b52b57ddc4e901400843d1aa6b836ca5326ade1ed7748b34dbacaee2d6ce6

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 KB

Contents

module FriendlyId

  module AcktiveRecord

    module Compat
      def self.scope_method
        ActiveRecord::VERSION::STRING >= "3" ? :scope : :named_scope
      end
    end

    include FriendlyId::Base

    def has_friendly_id(method, options = {})
      class_inheritable_accessor :friendly_id_config
      write_inheritable_attribute :friendly_id_config, Configuration.new(self, method, options)
      if friendly_id_config.use_slug?
        include SluggedModel
      else
        include SimpleModel
      end
    end

    private

    # Prevent the cached_slug column from being accidentally or maliciously
    # overwritten. Note that +attr_protected+ is used to protect the cached_slug
    # column, unless you have already invoked +attr_accessible+. So if you
    # wish to use +attr_accessible+, you must invoke it BEFORE you invoke
    # {#has_friendly_id} in your class.
    def protect_friendly_id_attributes
      # only protect the column if the class is not already using attributes_accessible
      if !accessible_attributes
        if friendly_id_config.custom_cache_column?
          attr_protected friendly_id_config.cache_column
        end
        attr_protected :cached_slug
      end
    end

  end
end

class ActiveRecord::Base
  extend FriendlyId::AcktiveRecord
end

require File.join(File.dirname(__FILE__), "acktive_record", "configuration")
require File.join(File.dirname(__FILE__), "acktive_record", "finders")
require File.join(File.dirname(__FILE__), "acktive_record", "simple_model")
require File.join(File.dirname(__FILE__), "acktive_record", "slugged_model")
require File.join(File.dirname(__FILE__), "acktive_record", "slug")
require File.join(File.dirname(__FILE__), "acktive_record", "tasks")

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
friendly_id-3.0.0.beta3 lib/friendly_id/active_record.rb
friendly_id-3.0.0.beta2 lib/friendly_id/active_record.rb
friendly_id-3.0.0.beta1 lib/friendly_id/active_record.rb