Module: ActsAsTaggableOn::Tagger::InstanceMethods

Defined in:
lib/acts_as_taggable_on/tagger.rb

Instance Method Summary collapse

Instance Method Details

#is_tagger?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/acts_as_taggable_on/tagger.rb', line 73

def is_tagger?
  tagger?
end

#tag(taggable, opts = {}) ⇒ Object

Tag a taggable model with tags that are owned by the tagger.

Example:

@user.tag(@photo, :with => "paris, normandy", :on => :locations)

Parameters:

  • taggable

    The object that will be tagged

  • options (Hash)

    An hash with options. Available options are:

    • :with - The tags that you want to

    • :on - The context on which you want to tag



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/acts_as_taggable_on/tagger.rb', line 56

def tag(taggable, opts={})
  opts.reverse_merge!(force: true)
  skip_save = opts.delete(:skip_save)
  return false unless taggable.respond_to?(:is_taggable?) && taggable.is_taggable?

  fail 'You need to specify a tag context using :on' unless opts.key?(:on)
  fail 'You need to specify some tags using :with' unless opts.key?(:with)
  fail "No context :#{opts[:on]} defined in #{taggable.class}" unless opts[:force] || taggable.tag_types.include?(opts[:on])

  taggable.set_owner_tag_list_on(self, opts[:on].to_s, opts[:with])
  taggable.save unless skip_save
end

#tagger?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/acts_as_taggable_on/tagger.rb', line 69

def tagger?
  self.class.is_tagger?
end