Class: CopyTunerClient::RequestSync
- Inherits:
-
Object
- Object
- CopyTunerClient::RequestSync
- Defined in:
- lib/copy_tuner_client/request_sync.rb
Overview
Rack middleware that synchronizes with CopyTuner during each request.
This is injected into the Rails middleware stack in development environments.
Constant Summary collapse
- VIEW_PATH =
File.('../../../ui/views/', __FILE__)
Instance Attribute Summary collapse
-
#last_synced ⇒ Object
Returns the value of attribute last_synced.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Invokes the upstream Rack application and flushes the cache after each request.
-
#initialize(app, options) ⇒ RequestSync
constructor
A new instance of RequestSync.
Constructor Details
#initialize(app, options) ⇒ RequestSync
Returns a new instance of RequestSync.
17 18 19 20 21 22 23 24 25 |
# File 'lib/copy_tuner_client/request_sync.rb', line 17 def initialize(app, ) @app = app @poller = [:poller] @cache = [:cache] @interval = [:interval] @ignore_regex = [:ignore_regex] @last_synced = [:last_synced] @first = true end |
Instance Attribute Details
#last_synced ⇒ Object
Returns the value of attribute last_synced.
27 28 29 |
# File 'lib/copy_tuner_client/request_sync.rb', line 27 def last_synced @last_synced end |
Instance Method Details
#call(env) ⇒ Object
Invokes the upstream Rack application and flushes the cache after each request.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/copy_tuner_client/request_sync.rb', line 31 def call(env) if /^\/copytuner/ =~ ::Rack::Request.new(env).path_info dup._call(env) else first_request = @first if first_request @first = false @cache.download end cancel_sync = cancel_sync?(env) response = @app.call(env) @poller.start_sync unless first_request || cancel_sync update_last_synced unless in_interval? response end end |