Module: DatabaseCachedAttribute::ClassMethods

Defined in:
lib/database_cached_attribute.rb

Instance Method Summary collapse

Instance Method Details

#database_cached_attribute(*attrs) ⇒ Object

Sets up cache invalidation callbacks for the provided attributes



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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