Module: MakeTaggable::Taggable::Related
- Defined in:
- lib/make_taggable/taggable/related.rb
Overview
Finding records that share tags with this one.
Results come back ordered by how many tags matched, most first, and carry that figure as a
count attribute.
Defined Under Namespace
Modules: CalculationMethods, ClassMethods
Class Method Summary collapse
- .included(base) ⇒ void private
Instance Method Summary collapse
-
#find_matching_contexts(search_context, result_context, options = {}) ⇒ ActiveRecord::Relation
Records of this model tagged, in one context, with the tags this record carries in another.
-
#find_matching_contexts_for(klass, search_context, result_context, options = {}) ⇒ ActiveRecord::Relation
As #find_matching_contexts, against another model.
-
#matching_contexts_for(search_context, result_context, klass, options = {}) ⇒ ActiveRecord::Relation
Builds the relation behind #find_matching_contexts.
-
#related_tags_for(context, klass, options = {}) ⇒ ActiveRecord::Relation
Builds the relation behind each generated
find_related_<context>method.
Class Method Details
.included(base) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
17 18 19 20 |
# File 'lib/make_taggable/taggable/related.rb', line 17 def self.included(base) base.extend MakeTaggable::Taggable::Related::ClassMethods base. end |
Instance Method Details
#find_matching_contexts(search_context, result_context, options = {}) ⇒ ActiveRecord::Relation
Records of this model tagged, in one context, with the tags this record carries in another.
66 67 68 |
# File 'lib/make_taggable/taggable/related.rb', line 66 def find_matching_contexts(search_context, result_context, = {}) matching_contexts_for(search_context.to_s, result_context.to_s, self.class, ) end |
#find_matching_contexts_for(klass, search_context, result_context, options = {}) ⇒ ActiveRecord::Relation
As #find_matching_contexts, against another model.
79 80 81 |
# File 'lib/make_taggable/taggable/related.rb', line 79 def find_matching_contexts_for(klass, search_context, result_context, = {}) matching_contexts_for(search_context.to_s, result_context.to_s, klass, ) end |
#matching_contexts_for(search_context, result_context, klass, options = {}) ⇒ ActiveRecord::Relation
Builds the relation behind #find_matching_contexts.
92 93 94 95 |
# File 'lib/make_taggable/taggable/related.rb', line 92 def matching_contexts_for(search_context, result_context, klass, = {}) = (search_context).map { |t| t.name } (klass, ["#{exclude_self(klass, id)} #{klass.table_name}.#{klass.primary_key} = #{MakeTaggable::Tagging.table_name}.taggable_id AND #{MakeTaggable::Tagging.table_name}.taggable_type = ? AND #{MakeTaggable::Tagging.table_name}.tag_id = #{MakeTaggable::Tag.table_name}.#{MakeTaggable::Tag.primary_key} AND #{MakeTaggable::Tag.table_name}.name IN (?) AND #{MakeTaggable::Tagging.table_name}.context = ?", klass.base_class.to_s, , result_context]) end |
#related_tags_for(context, klass, options = {}) ⇒ ActiveRecord::Relation
Builds the relation behind each generated find_related_<context> method.
106 107 108 109 110 |
# File 'lib/make_taggable/taggable/related.rb', line 106 def (context, klass, = {}) = Array.wrap([:ignore]).map(&:to_s) || [] = (context).map { |t| t.name }.reject { |t| .include? t } (klass, ["#{exclude_self(klass, id)} #{klass.table_name}.#{klass.primary_key} = #{MakeTaggable::Tagging.table_name}.taggable_id AND #{MakeTaggable::Tagging.table_name}.taggable_type = ? AND #{MakeTaggable::Tagging.table_name}.tag_id = #{MakeTaggable::Tag.table_name}.#{MakeTaggable::Tag.primary_key} AND #{MakeTaggable::Tag.table_name}.name IN (?) AND #{MakeTaggable::Tagging.table_name}.context = ?", klass.base_class.to_s, , context]) end |