class Frizz::Sync
Attributes
local[R]
remote[R]
Public Class Methods
new(local, remote)
click to toggle source
# File lib/frizz/sync.rb, line 3 def initialize(local, remote) @local = local @remote = remote end
Public Instance Methods
run!()
click to toggle source
# 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 = local_index[local_path] local_file_md5 = local_file && local_file.checksum if local_file_md5.nil? puts "#{local_path}: deleted".red remote.delete(remote_file) changes << remote_file.key elsif local_file_md5 == remote_file.etag.gsub('"', '') puts "#{local_path}: unchanged" local_index.delete(local_path) else puts "#{local_path}: updated".green upload(local_path, local_file) local_index.delete(local_path) changes << local_path end end # Upload new files local_index.each do |local_path, local_file| puts "#{local_path}: new".green upload(local_path, local_file) changes << local_path end changes end
Private Instance Methods
local_index()
click to toggle source
# File lib/frizz/sync.rb, line 50 def local_index @local_index ||= local.files.each_with_object({}) do |file, obj| obj[file.key] = file end end
upload(local_path, local_file)
click to toggle source
# File lib/frizz/sync.rb, line 56 def upload(local_path, local_file) remote.upload local.file_for(local_path), local_path, local_file.upload_options end