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



3
4
5
6
# File 'lib/acts_as_taggable_on/taggable/related.rb', line 3

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



30
31
32
# File 'lib/acts_as_taggable_on/taggable/related.rb', line 30

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



34
35
36
# File 'lib/acts_as_taggable_on/taggable/related.rb', line 34

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



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

def matching_contexts_for(search_context, result_context, klass, options = {})
  tags_to_find = tags_on(search_context).map { |t| t.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


43
44
45
46
47
# File 'lib/acts_as_taggable_on/taggable/related.rb', line 43

def related_tags_for(context, klass, options = {})
  tags_to_ignore = Array.wrap(options[:ignore]).map(&:to_s) || []
  tags_to_find = tags_on(context).map { |t| t.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