Sha256: 2cc06f859eb3f2685eda0ef7a79f4d56ac40f587454d542ce0f85e64a22bd854

Contents?: true

Size: 686 Bytes

Versions: 3

Compression:

Stored size: 686 Bytes

Contents

module Cachers
  class Base

    %i(extend include).each do |action|
      send action, Dsl
    end

    attr_reader :record

    def initialize(record)
      @record = record
    end

    def cache
      # Sublcass must implement this
    end

    def uncache
      # Subclass must implement this
    end

    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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cachers-5.1.2 lib/cachers/base.rb
cachers-5.1.1 lib/cachers/base.rb
cachers-4.1.0.2 lib/cachers/base.rb