Class: Archaeo::DownloadState
- Inherits:
-
Object
- Object
- Archaeo::DownloadState
- 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
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
Instance Method Summary collapse
- #clear ⇒ Object
- #completed?(timestamp) ⇒ Boolean
-
#initialize(output_dir) ⇒ DownloadState
constructor
A new instance of DownloadState.
- #mark_completed(timestamp) ⇒ Object
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_dir ⇒ Object (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
#clear ⇒ Object
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
21 22 23 |
# File 'lib/archaeo/download_state.rb', line 21 def completed?() .include?(.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() ts = .to_s return if .include?(ts) << ts @timestamps_set = nil save end |