Class: Datapimp::Sync::DropboxFolder
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Datapimp::Sync::DropboxFolder
- Defined in:
- lib/datapimp/sync/dropbox_folder.rb
Instance Method Summary collapse
-
#cursor ⇒ Object
The Dropbox Delta API uses a cursor to keep track of the last state the local filesystem has synced with.
- #cursor_path ⇒ Object
-
#delta ⇒ Object
Provides access to the Dropbox API Delta which will tell us how to modify the state of ‘local_path` to match what exists on Dropbox.
-
#dropbox ⇒ Object
Provides easy access to the Dropbox client.
- #ensure_remote_folder_exists ⇒ Object
-
#local_path ⇒ Object
A Pointer to the local path we will be syncing with the Dropbox remote.
- #remote_path ⇒ Object
- #remote_path_missing? ⇒ Boolean
- #remote_path_parent ⇒ Object
- #run(action, options = {}) ⇒ Object
Instance Method Details
#cursor ⇒ Object
The Dropbox Delta API uses a cursor to keep track of the last state the local filesystem has synced with. We store this in the syncable folder itself
23 24 25 |
# File 'lib/datapimp/sync/dropbox_folder.rb', line 23 def cursor cursor_path.exist? && cursor_path.read end |
#cursor_path ⇒ Object
27 28 29 |
# File 'lib/datapimp/sync/dropbox_folder.rb', line 27 def cursor_path local_path.join('.dropbox-cursor') end |
#delta ⇒ Object
Provides access to the Dropbox API Delta which will tell us how to modify the state of ‘local_path` to match what exists on Dropbox.
11 12 13 |
# File 'lib/datapimp/sync/dropbox_folder.rb', line 11 def delta @delta ||= dropbox.delta(cursor, remote_path) end |
#dropbox ⇒ Object
Provides easy access to the Dropbox client
4 5 6 |
# File 'lib/datapimp/sync/dropbox_folder.rb', line 4 def dropbox @dropbox ||= Datapimp::Sync.dropbox end |
#ensure_remote_folder_exists ⇒ Object
67 68 |
# File 'lib/datapimp/sync/dropbox_folder.rb', line 67 def ensure_remote_folder_exists end |
#local_path ⇒ Object
A Pointer to the local path we will be syncing with the Dropbox remote
16 17 18 |
# File 'lib/datapimp/sync/dropbox_folder.rb', line 16 def local_path Pathname(local) end |
#remote_path ⇒ Object
31 32 33 34 35 |
# File 'lib/datapimp/sync/dropbox_folder.rb', line 31 def remote_path dropbox.ls(remote) rescue(Dropbox::API::Error::NotFound) nil end |
#remote_path_missing? ⇒ Boolean
44 45 46 |
# File 'lib/datapimp/sync/dropbox_folder.rb', line 44 def remote_path_missing? remote_path.nil? end |
#remote_path_parent ⇒ Object
37 38 39 40 41 42 |
# File 'lib/datapimp/sync/dropbox_folder.rb', line 37 def remote_path_parent parent, _ = File.split(remote) dropbox.ls(parent) rescue(Dropbox::API::Error::NotFound) nil end |
#run(action, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/datapimp/sync/dropbox_folder.rb', line 48 def run(action, ={}) action = action.to_sym if action == :push if remote_path_missing? dropbox.mkdir(remote) end Dir[local_path.join("**/*")].each do |f| # Upload the file binding.pry end elsif action == :pull # TODO # Implement the Delta call end end |