Sha256: 924e1a89c519e9fe8255d2f423c04df3c6e9ae8135661dd0257c88ad3349c1cb

Contents?: true

Size: 791 Bytes

Versions: 3

Compression:

Stored size: 791 Bytes

Contents

# Adds surrogate key methods to ActiveRecord models
module FastlyRails
  module ActiveRecord
    module SurrogateKey
      extend ActiveSupport::Concern

      module ClassMethods

        def purge_all
          FastlyRails.client.get_service(service_id).purge_by_key(table_key)
        end

        def table_key
          table_name
        end

        def service_id
          FastlyRails.service_id
        end
      end

      def record_key
        "#{table_key}/#{id}"
      end

      def table_key
        self.class.table_key
      end

      def purge
        FastlyRails.client.get_service(service_id).purge_by_key(record_key)
      end

      def purge_all
        self.class.purge_all
      end

      def service_id
        self.class.service_id
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fastly-rails-0.1.5 lib/fastly-rails/active_record/surrogate_key.rb
fastly-rails-0.1.4 lib/fastly-rails/active_record/surrogate_key.rb
fastly-rails-0.1.3 lib/fastly-rails/active_record/surrogate_key.rb