Module: Dbox

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

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.authorizeObject



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

def self.authorize
  Dbox::API.authorize
end

.clone(remote_path, local_path) ⇒ Object



34
35
36
37
38
39
40
# 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

.create(remote_path, local_path) ⇒ Object



26
27
28
29
30
31
32
# 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

.exists?(local_path) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
# File 'lib/dbox.rb', line 64

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



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

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



42
43
44
45
46
47
# 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) ⇒ Object



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

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