Sha256: ffddadff10d28455b1418626755d20b66bafff64eff0779321401083b8d4ab19

Contents?: true

Size: 852 Bytes

Versions: 3

Compression:

Stored size: 852 Bytes

Contents

module CopycopterClient
  # Rack middleware that synchronizes with Copycopter during each request.
  #
  # This is injected into the Rails middleware stack in development environments.
  class RequestSync
    # @param app [Rack] the upstream app into whose responses to inject the editor
    # @param options [Hash]
    # @option options [Cache] :cache agent that should be flushed after each request
    def initialize(app, options)
      @app  = app
      @cache = options[:cache]
    end

    # Invokes the upstream Rack application and flushes the cache after each
    # request.
    def call(env)
      @cache.download unless asset_request?(env)
      response = @app.call(env)
      @cache.flush    unless asset_request?(env)
      response
    end

    private
    def asset_request?(env)
      env['PATH_INFO'] =~ /^\/assets/
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
copycopter_client-2.0.1 lib/copycopter_client/request_sync.rb
copycopter_client-2.0.0 lib/copycopter_client/request_sync.rb
copycopter_client-1.1.2 lib/copycopter_client/request_sync.rb