Module: RocketTag::Taggable::InstanceMethods
- Defined in:
- lib/rocket_tag/taggable.rb
Instance Method Summary collapse
- #cache_tags ⇒ Object
- #reload_with_tags(options = nil) ⇒ Object
-
#tagged_similar(options = {}) ⇒ Object
Find models with similar tags to the current model ordered is decending order of the number of matches.
- #tags_for_context(context) ⇒ Object
- #write_context(context, list) ⇒ Object
Instance Method Details
#cache_tags ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/rocket_tag/taggable.rb', line 83 def unless @tags_cached ||= send("taggings").group_by{|f| f.context } .each do |context,v| write_context context, v.map{|t| t.tag.name} end @tags_cached = true end end |
#reload_with_tags(options = nil) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/rocket_tag/taggable.rb', line 74 def ( = nil) self.class.rocket_tag.contexts.each do |context| write_context context, [] end @tags_cached = false () end |
#tagged_similar(options = {}) ⇒ Object
Find models with similar tags to the current model ordered is decending order of the number of matches
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/rocket_tag/taggable.rb', line 106 def tagged_similar = {} context = .delete :on contexts = self.class.normalize_contexts context, self.class.rocket_tag.contexts q = self.class.tagged_with Hash[*contexts.map{|c| [c, (c)] }.flatten(1)] # Exclude self from the results q.where{id!=my{id}} end |
#tags_for_context(context) ⇒ Object
98 99 100 101 |
# File 'lib/rocket_tag/taggable.rb', line 98 def context @contexts ||= {} @contexts[context.to_sym] || [] end |
#write_context(context, list) ⇒ Object
93 94 95 96 |
# File 'lib/rocket_tag/taggable.rb', line 93 def write_context context, list @contexts ||= {} @contexts[context.to_sym] = list end |