Sha256: edbae52c1ec4b9e66d19a1ecf29f0fa2f9bf156d036bb2fff7f9f141a7519578

Contents?: true

Size: 661 Bytes

Versions: 3

Compression:

Stored size: 661 Bytes

Contents

require "mengpaneel/strategy/base"

module Mengpaneel
  module Strategy
    class CapableClientSide < Base
      REQUEST_HEADER  = "X-Mengpaneel-Flush-Capable".freeze
      RESPONSE_HEADER = "X-Mengpaneel-Calls".freeze

      delegate :request, :response, to: :controller, allow_nil: true

      def run
        return false unless controller
        return false unless capable?

        return true if all_calls[:tracking].blank?

        response.headers[RESPONSE_HEADER] = JSON.dump(all_calls[:tracking])

        true
      end

      private
        def capable?
          %w(true 1).include?(request.headers[REQUEST_HEADER])
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mengpaneel-0.0.3 lib/mengpaneel/strategy/capable_client_side.rb
mengpaneel-0.0.2 lib/mengpaneel/strategy/capable_client_side.rb
mengpaneel-0.0.1 lib/mengpaneel/strategy/capable_client_side.rb