Sha256: f8428992ef97cf8546d0256043a0d6a3d8b9dcd9fd4187da06d104d154ebe028

Contents?: true

Size: 1.25 KB

Versions: 10

Compression:

Stored size: 1.25 KB

Contents

module Tagtical
  class Tagging < ::ActiveRecord::Base #:nodoc:
    include Tagtical::ActiveRecord::Backports if ::ActiveRecord::VERSION::MAJOR < 3

    attr_accessible :tag,
                    :tag_id,
                    :taggable,
                    :taggable_type,
                    :taggable_id,
                    :tagger,
                    :tagger_id,
                    :relevance

    belongs_to :tag, :class_name => 'Tagtical::Tag'
    belongs_to :taggable, :polymorphic => true

    validates_presence_of :tag_id
    validates_uniqueness_of :tag_id, :scope => [:taggable_type, :taggable_id, :tagger_id]

    if Tagtical.config.polymorphic_tagger?
      attr_accessible :tagger_type
       belongs_to :tagger, :polymorphic => true
    else
      belongs_to :tagger, case Tagtical.config.tagger
       when Hash then Tagtical.config.tagger
       when true then {:class_name => "User"} # default to using User class.
       when String then {:class_name => Tagtical.config.tagger}
                           end
    end


    before_create { |record| record.relevance ||= default_relevance }

    class_attribute :default_relevance, :instance_writer => false
    self.default_relevance = 1

    def <=>(tagging)
      relevance <=> tagging.relevance
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tagtical-1.3.1 lib/tagtical/tagging.rb
tagtical-1.3.0 lib/tagtical/tagging.rb
tagtical-1.2.0 lib/tagtical/tagging.rb
tagtical-1.1.3 lib/tagtical/tagging.rb
tagtical-1.1.2 lib/tagtical/tagging.rb
tagtical-1.1.1 lib/tagtical/tagging.rb
tagtical-1.1.0 lib/tagtical/tagging.rb
tagtical-1.0.8 lib/tagtical/tagging.rb
tagtical-1.0.7 lib/tagtical/tagging.rb
tagtical-1.0.6 lib/tagtical/tagging.rb