Class: CopycopterClient::RequestSync

Inherits:
Object
  • Object
show all
Defined in:
lib/copycopter_client/request_sync.rb

Overview

Rack middleware that synchronizes with Copycopter during each request.

This is injected into the Rails middleware stack in development environments.

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ RequestSync

Returns a new instance of RequestSync.

Parameters:

  • app (Rack)

    the upstream app into whose responses to inject the editor

  • options (Hash)

Options Hash (options):

  • :cache (Cache)

    agent that should be flushed after each request



9
10
11
12
# File 'lib/copycopter_client/request_sync.rb', line 9

def initialize(app, options)
  @app  = app
  @cache = options[:cache]
end

Instance Method Details

#call(env) ⇒ Object

Invokes the upstream Rack application and flushes the cache after each request.



16
17
18
19
20
21
# File 'lib/copycopter_client/request_sync.rb', line 16

def call(env)
  @cache.download unless asset_request?(env)
  response = @app.call(env)
  @cache.flush    unless asset_request?(env)
  response
end