Module: ActiveRecord::Extension::CachedColumn::ClassMethods

Defined in:
lib/vex/active_record/cached_column.rb

Instance Method Summary collapse

Instance Method Details

#cached_column(name, options = ActiveRecord::Extension::CachedColumn::DEFAULTS, &block) ⇒ Object

cached_column :name, :time_to_live => 5.minutes



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vex/active_record/cached_column.rb', line 13

def cached_column(name, options = ActiveRecord::Extension::CachedColumn::DEFAULTS, &block)
  #
  # create the "#{name}_updated_at_column"
  lite_table do
    datetime "#{name}_updated_at"
  end
  
  define_method(name) do
    read_cached_column(name, options, Proc.new)
  end
  
  define_method("#{name}!") do
    write_attribute "#{name}_updated_at", nil
    self.send name
  end
  
  define_method("#{name}=") do |v|
    write_cached_column(name, v)
  end
end