Module: Tagtical::Taggable::Cache

Defined in:
lib/tagtical/taggable/cache.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/tagtical/taggable/cache.rb', line 3

def self.included(base)
  # Skip adding caching capabilities if table not exists or no cache columns exist
  return unless base.table_exists? && base.tag_types.any? { |context| base.column_names.include?("cached_#{context.to_s.singularize}_list") }

  base.send :include, Tagtical::Taggable::Cache::InstanceMethods
  base.extend Tagtical::Taggable::Cache::ClassMethods
  
  base.class_eval do
    before_save :save_cached_tag_list        
  end
  
  base.initialize_tagtical_cache
end