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

Class Method Details

.call(document, author:, config:) ⇒ Docsmith::DocumentVersion?

Returns nil if within debounce or content unchanged.

Parameters:

Returns:



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: 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.

Parameters:

Returns:

  • (Boolean)


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