Module: Tagtical::Taggable

Defined in:
lib/tagtical/taggable.rb,
lib/tagtical/taggable/core.rb,
lib/tagtical/taggable/cache.rb,
lib/tagtical/taggable/related.rb,
lib/tagtical/taggable/ownership.rb,
lib/tagtical/taggable/tag_group.rb,
lib/tagtical/taggable/collection.rb

Defined Under Namespace

Modules: Cache, Collection, Core, Ownership, Related, TagGroup

Instance Method Summary collapse

Instance Method Details

#acts_as_taggable(*tag_types) ⇒ Object

Make a model taggable on specified contexts.

Example:

module Tag
  class Language < Tagtical::Tag
  end
  class Skill < Tagtical::Tag
  end
end
class User < ActiveRecord::Base
  acts_as_taggable :languages, :skills
end

Parameters:

  • tag_types (Array)

    An array of taggable contexts. These must have an associated subclass under Tag.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tagtical/taggable.rb', line 22

def acts_as_taggable(*tag_types)
  tag_types.flatten!
  tag_types << Tagtical::Tag::Type::BASE # always include the base type.
  tag_types = Tagtical::Tag::Type::Collection.new(Tagtical::Tag::Type.register(tag_types.uniq.compact, self))

  if taggable?
    self.tag_types = (self.tag_types + tag_types).uniq
  else
    class_attribute :tag_types, :custom_tag_types
    self.tag_types = tag_types
    self.custom_tag_types = tag_types - [Tagtical::Tag::Type::BASE]

    has_many :taggings, :as => :taggable, :dependent => :destroy, :include => :tag, :class_name => "Tagtical::Tagging"
    has_many :tags, :through => :taggings, :class_name => "Tagtical::Tag"
    validate :must_have_valid_tags

    class_eval do
      def self.taggable?
        true
      end
    end

    include Tagtical::Taggable::Core
    include Tagtical::Taggable::Collection
    include Tagtical::Taggable::Cache
    include Tagtical::Taggable::Ownership
    include Tagtical::Taggable::Related
    extend Tagtical::Taggable::TagGroup

  end

  # Purpose of this is to keep additional tagtical class level methods grouped
  # together with the acts_as_taggable call.
  yield if block_given?
end

#taggable?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/tagtical/taggable.rb', line 3

def taggable?
  false
end