Class: NeocitiesRed::Services::Site::Exporter
- Inherits:
-
Object
- Object
- NeocitiesRed::Services::Site::Exporter
- Defined in:
- lib/neocities_red/services/site/exporter.rb
Overview
Downloads all files from the remote Neocities site to the local filesystem.
Supports incremental pulls — files that haven't been updated since the last pull (and exist locally) are skipped. Progress is displayed per-file, or via a Whirly spinner in quiet mode. Pull metadata (timestamp and working directory) is persisted in the config file for future incremental pulls.
Instance Attribute Summary collapse
-
#app_config_path ⇒ String
readonly
Path to the config file for persisting pull metadata.
-
#client ⇒ NeocitiesRed::Client
readonly
The authenticated API client.
-
#data ⇒ Hash
readonly
The current config data (modified in-place with last pull info).
-
#sitename ⇒ String
readonly
The site name being exported.
Instance Method Summary collapse
-
#export(quiet: false, last_pull_time: nil, last_pull_loc: nil) ⇒ void
Downloads all site files to the current working directory.
-
#initialize(client, sitename, data, app_config_path, display:) ⇒ Exporter
constructor
A new instance of Exporter.
Constructor Details
#initialize(client, sitename, data, app_config_path, display:) ⇒ Exporter
Returns a new instance of Exporter.
49 50 51 52 53 54 55 56 |
# File 'lib/neocities_red/services/site/exporter.rb', line 49 def initialize(client, sitename, data, app_config_path, display:) @client = client @sitename = sitename @data = data @app_config_path = app_config_path @display = display @pastel = Pastel.new(eachline: "\n") end |
Instance Attribute Details
#app_config_path ⇒ String (readonly)
Returns path to the config file for persisting pull metadata.
42 43 44 |
# File 'lib/neocities_red/services/site/exporter.rb', line 42 def app_config_path @app_config_path end |
#client ⇒ NeocitiesRed::Client (readonly)
Returns the authenticated API client.
33 34 35 |
# File 'lib/neocities_red/services/site/exporter.rb', line 33 def client @client end |
#data ⇒ Hash (readonly)
Returns the current config data (modified in-place with last pull info).
39 40 41 |
# File 'lib/neocities_red/services/site/exporter.rb', line 39 def data @data end |
#sitename ⇒ String (readonly)
Returns the site name being exported.
36 37 38 |
# File 'lib/neocities_red/services/site/exporter.rb', line 36 def sitename @sitename end |
Instance Method Details
#export(quiet: false, last_pull_time: nil, last_pull_loc: nil) ⇒ void
This method returns an undefined value.
Downloads all site files to the current working directory.
After the download, persists the current timestamp and working directory to the config file for future incremental pulls.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/neocities_red/services/site/exporter.rb', line 67 def export(quiet: false, last_pull_time: nil, last_pull_loc: nil) if quiet Whirly.start spinner: ["😺", "😸", "😹", "😻", "😼", "😽", "🙀", "😿", "😾"], status: "Retrieving files for #{@pastel.bold @sitename}" end fetch_files(last_pull_time, last_pull_loc, quiet) data["LAST_PULL"] = { time: Time.now, loc: Dir.pwd } ::File.write(app_config_path, data.to_json) ensure Whirly.stop if quiet end |