Class: CKEditor5::Rails::VersionDetector
- Inherits:
-
Object
- Object
- CKEditor5::Rails::VersionDetector
- Includes:
- Singleton
- Defined in:
- lib/ckeditor5/rails/version_detector.rb
Constant Summary collapse
- NPM_PACKAGE =
'ckeditor5'
- CACHE_DURATION =
4 days in seconds
345_600
Instance Method Summary collapse
- #clear_cache! ⇒ Object
-
#initialize ⇒ VersionDetector
constructor
A new instance of VersionDetector.
- #latest_safe_version(current_version) ⇒ Object
Constructor Details
#initialize ⇒ VersionDetector
Returns a new instance of VersionDetector.
22 23 24 25 |
# File 'lib/ckeditor5/rails/version_detector.rb', line 22 def initialize @cache = {} @monitor = Monitor.new end |
Instance Method Details
#clear_cache! ⇒ Object
27 28 29 |
# File 'lib/ckeditor5/rails/version_detector.rb', line 27 def clear_cache! @monitor.synchronize { @cache.clear } end |
#latest_safe_version(current_version) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ckeditor5/rails/version_detector.rb', line 31 def latest_safe_version(current_version) @monitor.synchronize do cache_key = "#{current_version}_latest" return @cache[cache_key][:version] if valid_cache_entry?(cache_key) version = find_latest_safe_version(current_version) @cache[cache_key] = { version: version, timestamp: Time.now.to_i } version end end |