Sha256: 3b95d5240e5e08c3b784e5e11172fa8e9ce81a41f0c912d53a7eee313b909a1b

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'aepic'
require 'responders'

module Aepic
  module Concerns
    module Responder
      extend ActiveSupport::Concern

      include Responders::HttpCacheResponder

      private

      def do_http_cache?
        get? && (@http_cache != false) && persisted? && resource_item.respond_to?(:updated_at)
      end

      # @return [Boolean]
      def do_http_cache!
        last_modified = resource_item.updated_at
        etag = resource_collection

        resource_collection.each do |resource|
          last_modified = resource.updated_at if resource.updated_at > last_modified
        end if resource_collection.length > 1

        !controller.stale?(etag: etag, last_modified: last_modified)
      end

      # @return [Array] array of resources
      def resource_collection
        @resource_collection ||= resource.is_a?(Array) ? resource : resources
      end

      # @return [Object] just one resource
      def resource_item
        @resource_item ||= resource.is_a?(Array) ? resource.last : resource
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aepic-0.0.4 lib/aepic/concerns/responder.rb