Class: Dotsync::Manifest
- Inherits:
-
Object
- Object
- Dotsync::Manifest
- Defined in:
- lib/dotsync/utils/manifest.rb
Constant Summary collapse
- MANIFESTS_DIR =
"dotsync/manifests"
Instance Method Summary collapse
-
#initialize(dest_dir:, key:, xdg_data_home:) ⇒ Manifest
constructor
A new instance of Manifest.
-
#orphans(current_files) ⇒ Array<String>
Returns orphan absolute paths: files in old manifest but not in current_files.
-
#read ⇒ Array<String>
Returns array of relative file paths from stored manifest.
-
#write(files) ⇒ Object
Writes current file list to manifest.
Constructor Details
#initialize(dest_dir:, key:, xdg_data_home:) ⇒ Manifest
Returns a new instance of Manifest.
12 13 14 15 16 |
# File 'lib/dotsync/utils/manifest.rb', line 12 def initialize(dest_dir:, key:, xdg_data_home:) @dest_dir = dest_dir @key = key @manifest_path = File.join(xdg_data_home, MANIFESTS_DIR, "#{key}.json") end |
Instance Method Details
#orphans(current_files) ⇒ Array<String>
Returns orphan absolute paths: files in old manifest but not in current_files
39 40 41 42 43 |
# File 'lib/dotsync/utils/manifest.rb', line 39 def orphans(current_files) previous = read orphaned = previous - current_files orphaned.map { |file| File.join(@dest_dir, file) } end |
#read ⇒ Array<String>
Returns array of relative file paths from stored manifest
20 21 22 23 24 25 26 27 |
# File 'lib/dotsync/utils/manifest.rb', line 20 def read return [] unless File.exist?(@manifest_path) data = JSON.parse(File.read(@manifest_path)) Array(data["files"]) rescue JSON::ParserError [] end |
#write(files) ⇒ Object
Writes current file list to manifest
31 32 33 34 |
# File 'lib/dotsync/utils/manifest.rb', line 31 def write(files) FileUtils.mkdir_p(File.dirname(@manifest_path)) File.write(@manifest_path, JSON.pretty_generate({ "files" => files.sort })) end |