module DatabaseCachedAttribute::ClassMethods

Public Instance Methods

database_cached_attribute(*attrs) click to toggle source

Sets up cache invalidation callbacks for the provided attributes

# File lib/database_cached_attribute.rb, line 62
def database_cached_attribute(*attrs)
  attrs.each do |attr|
    define_method("invalidate_#{attr}") do |arg=nil| # default arg to allow before_blah callbacks
      invalidate_cache attr.to_sym
    end

    define_method("only_#{attr}_changed?") do 
      only_change? attr.to_sym
    end

    define_method("cache_#{attr}") do
      update_cache attr.to_sym
    end
  end
end