Sha256: 5729d4bcd8b3054672bedb3dc09ad5d9841f8cfc8bffb574471d60114a3bfa09

Contents?: true

Size: 1.54 KB

Versions: 12

Compression:

Stored size: 1.54 KB

Contents

module ActiveRecord
  module Acts
    module Tagger
      def self.included(base)
        base.extend ClassMethods
      end
      
      module ClassMethods
        def acts_as_tagger(opts={})
          has_many :owned_taggings, opts.merge(:as => :tagger, :dependent => :destroy, 
                                               :include => :tag, :class_name => "Tagging")
          has_many :owned_tags, :through => :owned_taggings, :source => :tag
          include ActiveRecord::Acts::Tagger::InstanceMethods
          extend ActiveRecord::Acts::Tagger::SingletonMethods       
        end
        
        def is_tagger?
          false
        end
      end
      
      module InstanceMethods
        def self.included(base)
        end
        
        def tag(taggable, opts={})
          opts.reverse_merge!(:force => true)

          return false unless taggable.respond_to?(:is_taggable?) && taggable.is_taggable?
          raise "You need to specify a tag context using :on" unless opts.has_key?(:on)
          raise "You need to specify some tags using :with" unless opts.has_key?(:with)
          raise "No context :#{opts[:on]} defined in #{taggable.class.to_s}" unless 
              ( opts[:force] || taggable.tag_types.include?(opts[:on]) )

          taggable.set_tag_list_on(opts[:on].to_s, opts[:with], self)
          taggable.save
        end
        
        def is_tagger?
          self.class.is_tagger?
        end
      end
      
      module SingletonMethods
        def is_tagger?
          true
        end
      end
      
    end
  end
end

Version data entries

12 entries across 12 versions & 7 rubygems

Version Path
johnsbrn-acts-as-taggable-on-1.0.5 lib/acts_as_taggable_on/acts_as_tagger.rb
lawrencepit-acts-as-taggable-on-1.0.1 lib/acts_as_taggable_on/acts_as_tagger.rb
mbleigh-acts-as-taggable-on-1.0.1 lib/acts_as_taggable_on/acts_as_tagger.rb
mbleigh-acts-as-taggable-on-1.0.2 lib/acts_as_taggable_on/acts_as_tagger.rb
ozataman-acts-as-taggable-on-1.0.3 lib/acts_as_taggable_on/acts_as_tagger.rb
slitz-acts-as-taggable-on-1.0.2.1 lib/acts_as_taggable_on/acts_as_tagger.rb
slitz-acts-as-taggable-on-1.0.2.2 lib/acts_as_taggable_on/acts_as_tagger.rb
slitz-acts-as-taggable-on-1.0.2.3 lib/acts_as_taggable_on/acts_as_tagger.rb
wideopenspaces-acts-as-taggable-on-1.0.3 lib/acts_as_taggable_on/acts_as_tagger.rb
yury-acts-as-taggable-on-1.0.2 lib/acts_as_taggable_on/acts_as_tagger.rb
yury-acts-as-taggable-on-1.0.3 lib/acts_as_taggable_on/acts_as_tagger.rb
wideopenspaces-acts-as-taggable-on-1.0.4 lib/acts_as_taggable_on/acts_as_tagger.rb