Module: Docsmith::AutoSave
- Defined in:
- lib/docsmith/auto_save.rb
Overview
Applies debounce logic before delegating to VersionManager.save! Extracted for independent testability.
Class Method Summary collapse
-
.call(document, author:, config:) ⇒ Docsmith::DocumentVersion?
Nil if within debounce or content unchanged.
-
.within_debounce?(document, config) ⇒ Boolean
Returns true if the debounce window has not yet elapsed.
Class Method Details
.call(document, author:, config:) ⇒ Docsmith::DocumentVersion?
Returns nil if within debounce or content unchanged.
11 12 13 14 15 |
# File 'lib/docsmith/auto_save.rb', line 11 def self.call(document, author:, config:) return nil if within_debounce?(document, config) VersionManager.save!(document, author: , config: config) end |
.within_debounce?(document, config) ⇒ Boolean
Returns true if the debounce window has not yet elapsed. Public so specs can assert on timing logic without mocking Time.
22 23 24 25 26 27 |
# File 'lib/docsmith/auto_save.rb', line 22 def self.within_debounce?(document, config) last_saved = document.last_versioned_at return false if last_saved.nil? Time.current < last_saved + config[:debounce].to_i end |