module ActsAsTaggableOn::Taggable::Core::ClassMethods

Public Instance Methods

initialize_acts_as_taggable_on_core() click to toggle source
# File lib/acts_as_taggable_on/social_stream.rb, line 4
def initialize_acts_as_taggable_on_core
  tag_types.map(&:to_s).each do |tags_type|
    tag_type         = tags_type.to_s.singularize
    context_taggings = "#{tag_type}_taggings".to_sym
    context_tags     = tags_type.to_sym

    class_eval do
      has_many context_taggings, :as => :taggable, :dependent => :destroy, :include => :tag, :class_name => "ActsAsTaggableOn::Tagging",
      :conditions => ["#{ActsAsTaggableOn::Tagging.table_name}.context = ?", tags_type]
      has_many context_tags, :through => context_taggings, :source => :tag, :class_name => "ActsAsTaggableOn::Tag"
    end

    class_eval %(
      def #{tag_type}_list
        tag_list_on('#{tags_type}')
      end

      def #{tag_type}_list=(new_tags)
        set_tag_list_on('#{tags_type}', new_tags)
      end

      def all_#{tags_type}_list
        all_tags_list_on('#{tags_type}')
      end
    )
  end
end