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
    
  
  
    
      Constant Summary
      collapse
    
    
      
        - NUM_TRIES =
          
        
- 3 
- TIME_BETWEEN_TRIES =
          
  
 
- 3 
      Class Method Summary
      collapse
    
    
  
  
    Class Method Details
    
      
  
  
    .authorize  ⇒ Object 
  
  
  
  
    | 
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 | 
 
    
      
  
  
    .clone_or_pull(remote_path, local_path)  ⇒ Object 
  
  
  
  
    | 
50
51
52
53
54
55
56 | # File 'lib/dbox.rb', line 50
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)  ⇒ 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 | 
 
    
      
  
  
    .delete(remote_path, local_path = nil)  ⇒ Object 
  
  
  
  
    | 
87
88
89
90
91
92
93
94
95
96 | # File 'lib/dbox.rb', line 87
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)  ⇒ Boolean 
  
  
  
  
    | 
81
82
83
84
85 | # File 'lib/dbox.rb', line 81
def self.exists?(local_path)
  local_path = clean_local_path(local_path)
  migrate_dbfile(local_path)
  Dbox::Database.exists?(local_path)
end | 
 
    
      
  
  
    .log  ⇒ Object 
  
  
  
  
    | 
18
19
20 | # File 'lib/dbox/loggable.rb', line 18
def self.log
  @logger ||= setup_logger
end | 
 
    
      
  
  
    .move(new_remote_path, local_path)  ⇒ Object 
  
  
  
  
    | 
73
74
75
76
77
78
79 | # File 'lib/dbox.rb', line 73
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 
  
  
  
  
    | 
58
59
60
61
62
63 | # File 'lib/dbox.rb', line 58
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  ⇒ Object 
  
  
  
  
    | 
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 
  
  
  
  
    | 
65
66
67
68
69
70
71 | # File 'lib/dbox.rb', line 65
def self.sync(local_path)
  log.debug "Syncing (local: #{local_path})"
  res = {}
  res[:pull] = pull(local_path)
  res[:push] = push(local_path)
  res
end |