Class: Archaeo::DownloadState

Inherits:
Object
  • Object
show all
Defined in:
lib/archaeo/download_state.rb

Overview

Tracks download progress for resume support.

Persists completed snapshot timestamps to a state file within the output directory, allowing interrupted downloads to resume without re-fetching already downloaded snapshots.

Constant Summary collapse

STATE_FILE =
".archaeo-state"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_dir) ⇒ DownloadState

Returns a new instance of DownloadState.



16
17
18
19
# File 'lib/archaeo/download_state.rb', line 16

def initialize(output_dir)
  @output_dir = output_dir
  @path = File.join(output_dir, STATE_FILE)
end

Instance Attribute Details

#output_dirObject (readonly)

Returns the value of attribute output_dir.



14
15
16
# File 'lib/archaeo/download_state.rb', line 14

def output_dir
  @output_dir
end

Instance Method Details

#clearObject



34
35
36
37
38
# File 'lib/archaeo/download_state.rb', line 34

def clear
  @timestamps = []
  @timestamps_set = nil
  FileUtils.rm_f(@path)
end

#completed?(timestamp) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/archaeo/download_state.rb', line 21

def completed?(timestamp)
  timestamps_set.include?(timestamp.to_s)
end

#mark_completed(timestamp) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/archaeo/download_state.rb', line 25

def mark_completed(timestamp)
  ts = timestamp.to_s
  return if timestamps_set.include?(ts)

  timestamps << ts
  @timestamps_set = nil
  save
end