Class: Cachers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cachers/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Base

Returns a new instance of Base.



10
11
12
# File 'lib/cachers/base.rb', line 10

def initialize(record)
  @record = record
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



8
9
10
# File 'lib/cachers/base.rb', line 8

def record
  @record
end

Instance Method Details

#cacheObject



14
15
16
# File 'lib/cachers/base.rb', line 14

def cache
  # Sublcass must implement this
end

#recacheObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cachers/base.rb', line 22

def recache
  if record.previous_changes.any?
    previous_record = record.dup
    record.previous_changes.each do |attribute, values|
      previous_record.send "#{attribute}=", values.first
    end
    previous_record.id = record.id
    self.class.new(previous_record).uncache
  else
    uncache
  end
  cache
end

#uncacheObject



18
19
20
# File 'lib/cachers/base.rb', line 18

def uncache
  # Subclass must implement this
end