Class: Cachers::Base
- Inherits:
-
Object
- Object
- Cachers::Base
- Defined in:
- lib/cachers/base.rb
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #cache ⇒ Object
-
#initialize(record) ⇒ Base
constructor
A new instance of Base.
- #recache ⇒ Object
- #uncache ⇒ Object
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
#record ⇒ Object (readonly)
Returns the value of attribute record.
8 9 10 |
# File 'lib/cachers/base.rb', line 8 def record @record end |
Instance Method Details
#cache ⇒ Object
14 15 16 |
# File 'lib/cachers/base.rb', line 14 def cache # Sublcass must implement this end |
#recache ⇒ Object
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 |
#uncache ⇒ Object
18 19 20 |
# File 'lib/cachers/base.rb', line 18 def uncache # Subclass must implement this end |