Sha256: 52c9a46ec92872897f1a75761aa689dcd9bf2e2c452105db4852adb8227eaf57
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
module ActsAsTaggableOn::Taggable module Cache def self.included(base) # Skip adding caching capabilities if no cache columns exist return unless base.tag_types.any? { |context| base.column_names.include?("cached_#{context.to_s.singularize}_list") } base.class_eval do before_save :save_cached_tag_list end base.tag_types.map(&:to_s).each do |tag_type| base.class_eval %( def self.caching_#{tag_type.singularize}_list? caching_tag_list_on?("#{tag_type}") end ) end base.extend ClassMethods include InstanceMethods end module ClassMethods def caching_tag_list_on?(context) column_names.include?("cached_#{context.to_s.singularize}_list") end end module InstanceMethods def save_cached_tag_list tag_types.map(&:to_s).each do |tag_type| if self.class.send("caching_#{tag_type.singularize}_list?") self["cached_#{tag_type.singularize}_list"] = tag_list_cache_on(tag_type.singularize).to_a.flatten.compact.join(', ') end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts-as-taggable-on-2.0.0.pre3 | lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb |