lib/dbox/db.rb in dbox-0.1.0 vs lib/dbox/db.rb in dbox-0.2.0

- old
+ new

@@ -1,29 +1,25 @@ module Dbox class DB + include Loggable + DB_FILE = ".dropbox.db" attr_accessor :local_path def self.create(remote_path, local_path) - puts "[db] Creating remote folder: #{remote_path}" + log.info "Creating remote folder: #{remote_path}" api.create_dir(remote_path) clone(remote_path, local_path) end def self.clone(remote_path, local_path) - puts "[db] Cloning #{remote_path} into #{local_path}" - case res = api.metadata(remote_path) - when Hash - raise "Remote path error" unless remote_path == res["path"] - db = new(local_path, res) - db.pull - when Net::HTTPNotFound - raise "Remote path does not exist" - else - raise "Clone failed: #{res.inspect}" - end + log.info "Cloning #{remote_path} into #{local_path}" + res = api.metadata(remote_path) + raise "Remote path error" unless remote_path == res["path"] + db = new(local_path, res) + db.pull end def self.load(local_path) db_file = db_file(local_path) if File.exists?(db_file) @@ -122,10 +118,12 @@ def db_file self.class.db_file(@local_path) end class DropboxBlob + include Loggable + attr_reader :path, :revision, :modified_at def initialize(db, res) @db = db @path = @db.remote_to_relative_path(res["path"]) @@ -233,11 +231,11 @@ end def pull prev = self.clone prev.freeze - puts "[db] pulling" + log.info "Pulling changes" res = api.metadata(remote_path) update(res) if contents_hash != prev.contents_hash reconcile(prev, :down) end @@ -245,11 +243,11 @@ end def push prev = self.clone prev.freeze - puts "[db] pushing" + log.info "Pushing changes" res = gather_info(@path) update(res) reconcile(prev, :up) subdirs.each {|d| d.push } end @@ -303,26 +301,26 @@ def dir? true end def create_local - puts "[fs] creating dir #{local_path}" + log.info "Creating dir: #{local_path}" saving_parent_timestamp do FileUtils.mkdir_p(local_path) update_file_timestamp end end def delete_local - puts "[fs] deleting dir #{local_path}" + log.info "Deleting dir: #{local_path}" saving_parent_timestamp do FileUtils.rm_r(local_path) end end def update_local - puts "[fs] updating dir #{local_path}" + log.info "Updating dir: #{local_path}" update_file_timestamp end def create_remote api.create_dir(remote_path) @@ -354,25 +352,25 @@ def dir? false end def create_local - puts "[fs] creating file #{local_path}" + log.info "Creating file: #{local_path}" saving_parent_timestamp do download update_file_timestamp end end def delete_local - puts "[fs] deleting file #{local_path}" + log.info "Deleting file: #{local_path}" saving_parent_timestamp do FileUtils.rm_rf(local_path) end end def update_local - puts "[fs] updating file #{local_path}" + log.info "Updating file: #{local_path}" download update_file_timestamp end def create_remote