Module: ActsAsTaggableOn::Taggable::Related::ClassMethods

Defined in:
lib/acts_as_taggable_on/taggable/related.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_taggable_on(*args) ⇒ Object



37
38
39
40
# File 'lib/acts_as_taggable_on/taggable/related.rb', line 37

def acts_as_taggable_on(*args)
  super(*args)
  initialize_acts_as_taggable_on_related
end


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/acts_as_taggable_on/taggable/related.rb', line 10

def initialize_acts_as_taggable_on_related
  tag_types.map(&:to_s).each do |tag_type|
    class_eval %(
      def find_related_#{tag_type}(options = {})
        related_tags_for('#{tag_type}', self.class, options)
      end
      alias_method :find_related_on_#{tag_type}, :find_related_#{tag_type}

      def find_related_#{tag_type}_for(klass, options = {})
        related_tags_for('#{tag_type}', klass, options)
      end
    )
  end

  unless tag_types.empty?
    class_eval %(
      def find_matching_contexts(search_context, result_context, options = {})
        matching_contexts_for(search_context.to_s, result_context.to_s, self.class, options)
      end

      def find_matching_contexts_for(klass, search_context, result_context, options = {})
        matching_contexts_for(search_context.to_s, result_context.to_s, klass, options)
      end
    )
  end
end