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.



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

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.



12
13
14
# File 'lib/archaeo/download_state.rb', line 12

def output_dir
  @output_dir
end

Instance Method Details

#clearObject



28
29
30
31
# File 'lib/archaeo/download_state.rb', line 28

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

#completed?(timestamp) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/archaeo/download_state.rb', line 19

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

#mark_completed(timestamp) ⇒ Object



23
24
25
26
# File 'lib/archaeo/download_state.rb', line 23

def mark_completed(timestamp)
  timestamps << timestamp.to_s
  save
end