directory-digest 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/directory-digest/digest.rb +23 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef4b4013107b377353e4d89fada140859d4c7bda
4
- data.tar.gz: f95509c94e21089e8d3cd883c7ac17754a0ad386
3
+ metadata.gz: 122099030f505761a308d07fdef2bbe5e79d8299
4
+ data.tar.gz: 16bb9961a3851fb1dfaf31ba194ae7bcdeadb629
5
5
  SHA512:
6
- metadata.gz: 9dd2caa53cb69acdb34d3ac6268834c495592dbc3acc3157941ee89aad108c0b78ee0df84f63f989960a75c246fa70b66d27d61c2ff6f72255cc20d54f0163b8
7
- data.tar.gz: 97f28585f3de4014215505aaf1aba5dcb7c213bed285fc2ef20dd9f4a003bd40b9ee2bb28701ec3b115fcbe6b21175ad40dabbce3ecdb0c0ddd4e82739d7d05d
6
+ metadata.gz: b2c22e61c9ffc3d17842321460095b8c2ecab18c8f777f2bcecb7dc6ef99061dcc4000e3292cab0514aebeb6312fb6f09b3d29f744b5327d9850db0fa9f28211
7
+ data.tar.gz: de1739a9d67f4967c7b7bdd0f4cabecf383cbb3c86e1c6b3bbb84bbf72a1a35c116275e74e967549a2aa8dc917b1bd4be4d9426fe95f81a02e4d5f9df6b40075
@@ -57,8 +57,7 @@ module DirectoryDigest
57
57
  }
58
58
  end
59
59
 
60
- def mirror_from(other, log = proc { |_| })
61
- log.call("synchronizing #{other.directory} to #{directory}")
60
+ def mirror_from(other, actions = MirrorActions.new)
62
61
  files_copied = 0
63
62
  files_deleted = 0
64
63
  changes = changes_relative_to(other)
@@ -66,25 +65,14 @@ module DirectoryDigest
66
65
  source_path = "#{other.directory}#{path}"
67
66
  destination_path = "#{directory}#{path}"
68
67
  destination_directory = File.dirname(destination_path)
69
- unless Dir.exist?(destination_directory)
70
- log.call("create directory #{destination_directory}")
71
- FileUtils.makedirs(destination_directory)
72
- end
73
- log.call("copy #{source_path} to #{destination_path}")
74
- File.open(source_path, 'rb') do |source_file|
75
- File.open(destination_path, 'wb') do |destination_file|
76
- destination_file.write(source_file.read(4096)) until source_file.eof?
77
- end
78
- end
68
+ actions.create_directory(destination_directory) unless Dir.exist?(destination_directory)
69
+ actions.copy_file(source_path, destination_path)
79
70
  files_copied += 1
80
71
  end
81
72
  changes[:added].each do |path, _|
82
- destination_path = "#{directory}#{path}"
83
- log.call("delete #{destination_path}")
84
- File.delete(destination_path)
73
+ actions.delete_file("#{directory}#{path}")
85
74
  files_deleted += 1
86
75
  end
87
- log.call("synchronized - files copied: #{files_copied} - files deleted: #{files_deleted}")
88
76
  { files_copied: files_copied, files_deleted: files_deleted }
89
77
  end
90
78
 
@@ -97,4 +85,23 @@ module DirectoryDigest
97
85
  Digest.new(json['directory'], json['directory_digest'], json['file_digests'])
98
86
  end
99
87
  end
88
+
89
+ # DirectoryDigest::MirrorActions - Provider for standard mirror making activities
90
+ class MirrorActions
91
+ def create_directory(directory)
92
+ FileUtils.makedirs(directory)
93
+ end
94
+
95
+ def copy_file(source, destination)
96
+ File.open(source, 'rb') do |source_file|
97
+ File.open(destination, 'wb') do |destination_file|
98
+ destination_file.write(source_file.read(4096)) until source_file.eof?
99
+ end
100
+ end
101
+ end
102
+
103
+ def delete_file(filename)
104
+ File.delete(filename)
105
+ end
106
+ end
100
107
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directory-digest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Heald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-21 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake