Module: Dbox

Defined in:
lib/dbox.rb,
lib/dbox/db.rb,
lib/dbox/api.rb,
lib/dbox/utils.rb,
lib/dbox/syncer.rb,
lib/dbox/database.rb,
lib/dbox/loggable.rb

Defined Under Namespace

Modules: Loggable, Utils Classes: API, BadPath, ConfigurationError, CorruptDatabase, DB, Database, DatabaseError, MissingDatabase, RemoteAlreadyExists, RemoteMissing, RequestDenied, ServerError, Syncer

Class Method Summary collapse

Class Method Details

.authorizeObject



23
24
25
# File 'lib/dbox.rb', line 23

def self.authorize
  Dbox::API.authorize
end

.clone(remote_path, local_path) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/dbox.rb', line 35

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

.create(remote_path, local_path) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/dbox.rb', line 27

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

.exists?(local_path) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
# File 'lib/dbox.rb', line 73

def self.exists?(local_path)
  local_path = clean_local_path(local_path)
  migrate_dbfile(local_path)
  Dbox::Database.exists?(local_path)
end

.logObject



18
19
20
# File 'lib/dbox/loggable.rb', line 18

def self.log
  @logger ||= setup_logger
end

.move(new_remote_path, local_path) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/dbox.rb', line 65

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) ⇒ Object



43
44
45
46
47
48
# File 'lib/dbox.rb', line 43

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) ⇒ Object



50
51
52
53
54
55
# File 'lib/dbox.rb', line 50

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_loggerObject



22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/dbox.rb', line 57

def self.sync(local_path)
  log.debug "Syncing (local: #{local_path})"
  res = {}
  res[:pull] = pull(local_path)
  res[:push] = push(local_path)
  res
end