Module: ActsAsTaggableOn::Taggable::Core::ClassMethods

Defined in:
lib/acts_as_taggable_on/social_stream.rb

Instance Method Summary collapse

Instance Method Details

#initialize_acts_as_taggable_on_coreObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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