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 |
# File 'lib/copy_tuner_client/request_sync.rb', line 17 def initialize(app, ) @app = app @cache = [:cache] @interval = [:interval] @ignore_regex = [:ignore_regex] @last_synced = [:last_synced] end |
Instance Attribute Details
#last_synced ⇒ Object
Returns the value of attribute last_synced.
25 26 27 |
# File 'lib/copy_tuner_client/request_sync.rb', line 25 def last_synced @last_synced end |
Instance Method Details
#call(env) ⇒ Object
Invokes the upstream Rack application and flushes the cache after each request.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/copy_tuner_client/request_sync.rb', line 29 def call(env) if /^\/copytuner/ =~ ::Rack::Request.new(env).path_info dup._call(env) else @cache.download unless cancel_sync?(env) response = @app.call(env) @cache.flush unless cancel_sync?(env) update_last_synced unless in_interval? response end end |