lib/dbox/db.rb in dbox-0.4.4 vs lib/dbox/db.rb in dbox-0.5.0
- old
+ new
@@ -7,11 +7,11 @@
include Loggable
DB_FILE = ".dropbox.db"
DB_TMPFILE = ".dropbox.db.tmp"
- attr_accessor :local_path
+ attr_accessor :local_path, :remote_path, :root
def self.create(remote_path, local_path)
api.create_dir(remote_path)
clone(remote_path, local_path)
end
@@ -58,10 +58,14 @@
else
raise MissingDatabase, "No DB file found in #{local_path}"
end
end
+ def self.destroy!(local_path)
+ FileUtils.rm(db_file(local_path)) if exists?(local_path)
+ end
+
# IMPORTANT: DropboxDb.new is private. Please use DropboxDb.create, DropboxDb.clone, or DropboxDb.load as the entry point.
private_class_method :new
def initialize(local_path, res)
@local_path = local_path
@remote_path = res["path"]
@@ -231,12 +235,22 @@
def create_remote; raise RuntimeError, "Not implemented"; end
def delete_remote; raise RuntimeError, "Not implemented"; end
def update_remote; raise RuntimeError, "Not implemented"; end
def modified?(res)
- out = !(@revision == res["revision"] && @modified_at == parse_time(res["modified"]))
- log.debug "#{path}.modified? r#{@revision} =? r#{res["revision"]}, #{@modified_at} =? #{parse_time(res["modified"])} => #{out}"
+ out = !(@revision == res["revision"] && time_to_s(@modified_at) == time_to_s(res["modified"]))
+ log.debug "#{path} modified? => #{out}"
out
+ end
+
+ def time_to_s(t)
+ case t
+ when Time
+ # matches dropbox time format
+ t.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
+ when String
+ t
+ end
end
def parse_time(t)
case t
when Time