Sha256: 3c22a6ebea39d49f4e459fe5474cb8ad2f624499c99db610c36d3183d4aed231

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

# Adds surrogate key methods to ActiveRecord models
# Purge methods use a POST over PURGE
# The choice of this HTTP method should not effect anything
module FastlyRails
  module ActiveRecord
    module SurrogateKey
      extend ActiveSupport::Concern

      module ClassMethods

        def purge_all
          FastlyRails.purge_by_key(table_key)
        end

        def soft_purge_all
          FastlyRails.purge_by_key(table_key, true)
        end

        def table_key
          table_name
        end

        def fastly_service_identifier
          FastlyRails.service_id
        end
      end

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

      def table_key
        self.class.table_key
      end

      def purge
        FastlyRails.purge_by_key(record_key)
      end

      def soft_purge
        FastlyRails.purge_by_key(record_key, true)
      end

      def purge_all
        self.class.purge_all
      end

      def soft_purge_all
        self.class.soft_purge_all
      end

      def fastly_service_identifier
        self.class.fastly_service_identifier
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fastly-rails-0.8.0 lib/fastly-rails/active_record/surrogate_key.rb
fastly-rails-0.7.1 lib/fastly-rails/active_record/surrogate_key.rb
fastly-rails-0.7.0 lib/fastly-rails/active_record/surrogate_key.rb