Class: Frizz::Sync
- Inherits:
-
Object
- Object
- Frizz::Sync
- Defined in:
- lib/frizz/sync.rb
Instance Method Summary collapse
-
#initialize(local, remote) ⇒ Sync
constructor
A new instance of Sync.
- #run! ⇒ Object
Constructor Details
#initialize(local, remote) ⇒ Sync
Returns a new instance of Sync.
3 4 5 6 |
# File 'lib/frizz/sync.rb', line 3 def initialize(local, remote) @local = local @remote = remote end |
Instance Method Details
#run! ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/frizz/sync.rb', line 8 def run! changes = [] # Sync existing files remote.files.each do |remote_file| local_path = remote_file.key local_file_md5 = local_index[local_path] if local_file_md5.nil? puts "#{local_path}: deleted".red remote_file.destroy changes << remote_file.key elsif local_file_md5 == remote_file.etag puts "#{local_path}: unchanged" local_index.delete(local_path) else puts "#{local_path}: updated".green remote.upload local.file_for(local_path), local_path local_index.delete(local_path) changes << local_path end end # Upload new files local_index.each do |local_path, md5| puts "#{local_path}: new".green remote.upload local.file_for(local_path), local_path changes << local_path end changes end |