Class: WCC::Contentful::Middleman::Extension::ContentfulSyncUpdate
- Inherits:
-
Object
- Object
- WCC::Contentful::Middleman::Extension::ContentfulSyncUpdate
- Defined in:
- lib/wcc/contentful/middleman/extension.rb
Overview
Rack app that advances the sync engine whenever we load a page
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ContentfulSyncUpdate
constructor
A new instance of ContentfulSyncUpdate.
Constructor Details
#initialize(app) ⇒ ContentfulSyncUpdate
Returns a new instance of ContentfulSyncUpdate.
62 63 64 |
# File 'lib/wcc/contentful/middleman/extension.rb', line 62 def initialize(app) @app = app end |
Class Method Details
.last_sync ⇒ Object
76 77 78 |
# File 'lib/wcc/contentful/middleman/extension.rb', line 76 def last_sync @@last_sync ||= Time.at(0) # rubocop:disable Style/ClassVars end |
.last_sync=(time) ⇒ Object
80 81 82 |
# File 'lib/wcc/contentful/middleman/extension.rb', line 80 def last_sync=(time) @@last_sync = time # rubocop:disable Style/ClassVars end |
Instance Method Details
#call(env) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/wcc/contentful/middleman/extension.rb', line 66 def call(env) if (Time.now - ContentfulSyncUpdate.last_sync) > 10.seconds ::WCC::Contentful::Services.instance.sync_engine&.next ContentfulSyncUpdate.last_sync = Time.now end @app.call(env) end |