Module: Tagtical::Tagger::InstanceMethods

Defined in:
lib/tagtical/acts_as_tagger.rb

Instance Method Summary collapse

Instance Method Details

#is_tagger?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/tagtical/acts_as_tagger.rb', line 58

def is_tagger?
  self.class.is_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

    • :overwrite - true if you want to replace the tags with this new list.

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



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tagtical/acts_as_tagger.rb', line 45

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_owner_tag_list_on(self, opts[:on].to_s, opts[:with])
  taggable.save
end