Module: ActsAsTaggableOn::Taggable::Related

Defined in:
lib/acts-as-taggable-on/taggable/related.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
# File 'lib/acts-as-taggable-on/taggable/related.rb', line 6

def self.included(base)
  base.extend ActsAsTaggableOn::Taggable::Related::ClassMethods
  base.initialize_acts_as_taggable_on_related
end

Instance Method Details

#find_matching_contexts(search_context, result_context, options = {}) ⇒ Object



33
34
35
# File 'lib/acts-as-taggable-on/taggable/related.rb', line 33

def find_matching_contexts(search_context, result_context, options = {})
  matching_contexts_for(search_context.to_s, result_context.to_s, self.class, options)
end

#find_matching_contexts_for(klass, search_context, result_context, options = {}) ⇒ Object



37
38
39
# File 'lib/acts-as-taggable-on/taggable/related.rb', line 37

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

#matching_contexts_for(search_context, result_context, klass, _options = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/acts-as-taggable-on/taggable/related.rb', line 41

def matching_contexts_for(search_context, result_context, klass, _options = {})
  tags_to_find = tags_on(search_context).map(&:name)
  related_where(klass,
                [
                  "#{exclude_self(klass,
                                  id)} #{klass.table_name}.#{klass.primary_key} = #{ActsAsTaggableOn::Tagging.table_name}.taggable_id AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = '#{klass.base_class}' AND #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key} AND #{ActsAsTaggableOn::Tag.table_name}.name IN (?) AND #{ActsAsTaggableOn::Tagging.table_name}.context = ?", tags_to_find, result_context
                ])
end


50
51
52
53
54
55
56
57
58
# File 'lib/acts-as-taggable-on/taggable/related.rb', line 50

def related_tags_for(context, klass, options = {})
  tags_to_ignore = Array.wrap(options[:ignore]).map(&:to_s) || []
  tags_to_find = tags_on(context).map(&:name).reject { |t| tags_to_ignore.include? t }
  related_where(klass,
                [
                  "#{exclude_self(klass,
                                  id)} #{klass.table_name}.#{klass.primary_key} = #{ActsAsTaggableOn::Tagging.table_name}.taggable_id AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = '#{klass.base_class}' AND #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key} AND #{ActsAsTaggableOn::Tag.table_name}.name IN (?) AND #{ActsAsTaggableOn::Tagging.table_name}.context = ?", tags_to_find, context
                ])
end