Module: ActsAsTaggableOn::Tagger::ClassMethods

Defined in:
lib/acts_as_taggable_on/tagger.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_tagger(opts = {}) ⇒ Object

Make a model a tagger. This allows an instance of a model to claim ownership of tags.

Example:

class User < ActiveRecord::Base
  acts_as_tagger
end


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/acts_as_taggable_on/tagger.rb', line 16

def acts_as_tagger(opts={})
  class_eval do
    owned_taggings_scope = opts.delete(:scope)

    has_many :owned_taggings, owned_taggings_scope,
             opts.merge(
               as: :tagger,
               class_name: '::ActsAsTaggableOn::Tagging',
               dependent: :destroy
             )

    has_many :owned_tags, -> { distinct },
             class_name: '::ActsAsTaggableOn::Tag',
             source: :tag,
             through: :owned_taggings
  end

  include ActsAsTaggableOn::Tagger::InstanceMethods
  extend ActsAsTaggableOn::Tagger::SingletonMethods
end

#is_tagger?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/acts_as_taggable_on/tagger.rb', line 41

def is_tagger?
  tagger?
end

#tagger?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/acts_as_taggable_on/tagger.rb', line 37

def tagger?
  false
end