Module: Cash::WriteThrough::InstanceMethods

Defined in:
lib/cash/write_through.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(active_record_class) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/cash/write_through.rb', line 13

def self.included(active_record_class)
  active_record_class.class_eval do
    after_create :add_to_caches
    after_update :update_caches
    after_destroy :remove_from_caches
  end
end

Instance Method Details

#add_to_cachesObject



21
22
23
# File 'lib/cash/write_through.rb', line 21

def add_to_caches
  InstanceMethods.unfold(self.class, :add_to_caches, self)
end

#expire_cachesObject



34
35
36
# File 'lib/cash/write_through.rb', line 34

def expire_caches
  InstanceMethods.unfold(self.class, :expire_caches, self)
end

#remove_from_cachesObject



29
30
31
32
# File 'lib/cash/write_through.rb', line 29

def remove_from_caches
  return if new_record?
  InstanceMethods.unfold(self.class, :remove_from_caches, self)
end

#shallow_cloneObject



38
39
40
41
42
43
# File 'lib/cash/write_through.rb', line 38

def shallow_clone
  clone = self.class.new
  clone.instance_variable_set("@attributes", instance_variable_get(:@attributes))
  clone.instance_variable_set("@new_record", new_record?)
  clone
end

#update_cachesObject



25
26
27
# File 'lib/cash/write_through.rb', line 25

def update_caches
  InstanceMethods.unfold(self.class, :update_caches, self)
end