module Dbox
Constants
- NUM_TRIES
- TIME_BETWEEN_TRIES
Public Class Methods
clone(remote_path, local_path)
click to toggle source
# File lib/dbox.rb, line 34 def self.clone(remote_path, local_path) log.debug "Cloning (remote: #{remote_path}, local: #{local_path})" remote_path = clean_remote_path(remote_path) local_path = clean_local_path(local_path) migrate_dbfile(local_path) Dbox::Syncer.clone(remote_path, local_path) end
clone_or_pull(remote_path, local_path)
click to toggle source
# File lib/dbox.rb, line 49 def self.clone_or_pull(remote_path, local_path) if exists?(local_path) pull(local_path) else clone(remote_path, local_path) end end
create(remote_path, local_path)
click to toggle source
# File lib/dbox.rb, line 26 def self.create(remote_path, local_path) log.debug "Creating (remote: #{remote_path}, local: #{local_path})" remote_path = clean_remote_path(remote_path) local_path = clean_local_path(local_path) migrate_dbfile(local_path) Dbox::Syncer.create(remote_path, local_path) end
delete(remote_path, local_path = nil)
click to toggle source
# File lib/dbox.rb, line 86 def self.delete(remote_path, local_path = nil) log.debug "Deleting (remote: #{remote_path})" remote_path = clean_remote_path(remote_path) Dbox::Syncer.api.delete_dir(remote_path) if local_path local_path = clean_local_path(local_path) log.debug "Deleting (local_path: #{local_path})" FileUtils.rm_rf(local_path) if File.exists?(local_path) end end
exists?(local_path)
click to toggle source
# File lib/dbox.rb, line 80 def self.exists?(local_path) local_path = clean_local_path(local_path) migrate_dbfile(local_path) Dbox::Database.exists?(local_path) end
log()
click to toggle source
# File lib/dbox/loggable.rb, line 18 def self.log @logger ||= setup_logger end
metadata(remote_path)
click to toggle source
# File lib/dbox.rb, line 97 def self.metadata(remote_path) log.debug "Getting metadata for #{remote_path}" remote_path = clean_remote_path(remote_path) Dbox::Syncer.api.metadata(remote_path) end
move(new_remote_path, local_path)
click to toggle source
# File lib/dbox.rb, line 72 def self.move(new_remote_path, local_path) log.debug "Moving (new remote: #{new_remote_path}, local: #{local_path})" new_remote_path = clean_remote_path(new_remote_path) local_path = clean_local_path(local_path) migrate_dbfile(local_path) Dbox::Syncer.move(new_remote_path, local_path) end
pull(local_path)
click to toggle source
# File lib/dbox.rb, line 42 def self.pull(local_path) log.debug "Pulling (local: #{local_path})" local_path = clean_local_path(local_path) migrate_dbfile(local_path) Dbox::Syncer.pull(local_path) end
push(local_path)
click to toggle source
# File lib/dbox.rb, line 57 def self.push(local_path) log.debug "Pushing (local: #{local_path})" local_path = clean_local_path(local_path) migrate_dbfile(local_path) Dbox::Syncer.push(local_path) end
setup_logger()
click to toggle source
# File lib/dbox/loggable.rb, line 22 def self.setup_logger if defined?(LOGGER) LOGGER elsif defined?(Rails.logger) Rails.logger else l = Logger.new(STDOUT) l.level = (ENV["DEBUG"] && ENV["DEBUG"] != "false") ? Logger::DEBUG : Logger::INFO l.formatter = proc {|severity, datetime, progname, msg| "[#{severity}] #{msg}\n" } l end end
sync(local_path)
click to toggle source
# File lib/dbox.rb, line 64 def self.sync(local_path) log.debug "Syncing (local: #{local_path})" res = {} res[:pull] = pull(local_path) res[:push] = push(local_path) res end
Private Class Methods
clean_local_path(path)
click to toggle source
# File lib/dbox.rb, line 111 def self.clean_local_path(path) raise(ArgumentError, "Missing local path") unless path File.expand_path(path) end
clean_remote_path(path)
click to toggle source
# File lib/dbox.rb, line 105 def self.clean_remote_path(path) raise(ArgumentError, "Missing remote path") unless path path.sub(/\/$/,'') path[0].chr == "/" ? path : "/#{path}" end
migrate_dbfile(path)
click to toggle source
# File lib/dbox.rb, line 116 def self.migrate_dbfile(path) if Dbox::DB.exists?(path) log.warn "Old database file format found -- migrating to new database format" Dbox::Database.migrate_from_old_db_format(Dbox::DB.load(path)) Dbox::DB.destroy!(path) log.warn "Migration complete" end end