Class: Dropbox::Entry
Overview
A façade over a Dropbox::Session that allows the programmer to interact with Dropbox files in an object-oriented manner. The Dropbox::Entry instance is created by calling the Dropbox::API#entry method:
file = session.file('remote/file.pdf')
dir = session.directory('remote/dir') # these calls are actually identical
Note that no network calls are made; this merely creates a façade that will delegate future calls to the session:
file.move('new/path') # identical to calling session.move('remote/file.pdf', 'new/path')
The internal path is updated as the file is moved and renamed:
file = session.file('first_name.txt')
file.rename('second_name.txt')
file.rename('third_name.txt') # works as the internal path is updated with the first rename
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
The remote path of the file.
Instance Method Summary collapse
-
#copy(dest, options = {}) ⇒ Object
(also: #cp)
Delegates to Dropbox::API#copy.
-
#delete(options = {}) ⇒ Object
(also: #rm)
Delegates to Dropbox::API#delete.
-
#download(options = {}) ⇒ Object
(also: #body)
Delegates to Dropbox::API#download.
-
#initialize(session, path) ⇒ Entry
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#link(options = {}) ⇒ Object
Delegates to Dropbox::API#link.
-
#list(options = {}) ⇒ Object
(also: #ls)
Delegates to Dropbox::API#list.
-
#metadata(options = {}) ⇒ Object
(also: #info)
Delegates to Dropbox::API#metadata.
-
#move(dest, options = {}) ⇒ Object
(also: #mv)
Delegates to Dropbox::API#move.
-
#rename(name, options = {}) ⇒ Object
Delegates to Dropbox::API#rename.
-
#thumbnail(*args) ⇒ Object
Delegates to Dropbox::API#thumbnail.
Constructor Details
#initialize(session, path) ⇒ Entry
:nodoc:
29 30 31 32 |
# File 'lib/dropbox/entry.rb', line 29 def initialize(session, path) # :nodoc: @session = session @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
The remote path of the file.
27 28 29 |
# File 'lib/dropbox/entry.rb', line 27 def path @path end |
Instance Method Details
#copy(dest, options = {}) ⇒ Object Also known as: cp
Delegates to Dropbox::API#copy.
73 74 75 |
# File 'lib/dropbox/entry.rb', line 73 def copy(dest, ={}) @session.copy path, dest, end |
#delete(options = {}) ⇒ Object Also known as: rm
Delegates to Dropbox::API#delete.
80 81 82 |
# File 'lib/dropbox/entry.rb', line 80 def delete(={}) @session.delete path, end |
#download(options = {}) ⇒ Object Also known as: body
Delegates to Dropbox::API#download.
87 88 89 |
# File 'lib/dropbox/entry.rb', line 87 def download(={}) @session.download path, end |
#inspect ⇒ Object
:nodoc:
104 105 106 |
# File 'lib/dropbox/entry.rb', line 104 def inspect # :nodoc: "#<#{self.class.to_s} #{path}>" end |
#link(options = {}) ⇒ Object
Delegates to Dropbox::API#link.
100 101 102 |
# File 'lib/dropbox/entry.rb', line 100 def link(={}) @session.link path, end |
#list(options = {}) ⇒ Object Also known as: ls
Delegates to Dropbox::API#list
49 50 51 |
# File 'lib/dropbox/entry.rb', line 49 def list(={}) @session.list path, end |
#metadata(options = {}) ⇒ Object Also known as: info
Delegates to Dropbox::API#metadata. Additional options:
force-
Normally, subsequent calls to this method will use cached results if the file hasn’t been changed. To download the full metadata even if the file has not been changed, set this to
true.
41 42 43 44 |
# File 'lib/dropbox/entry.rb', line 41 def (={}) @previous_metadata = nil if .delete(:force) @previous_metadata = @session. path, (@previous_metadata ? .merge(:prior_response => @previous_metadata) : ) end |
#move(dest, options = {}) ⇒ Object Also known as: mv
Delegates to Dropbox::API#move.
56 57 58 59 60 |
# File 'lib/dropbox/entry.rb', line 56 def move(dest, ={}) result = @session.move(path, dest, ) @path = result.path.gsub(/^\//, '') return result end |
#rename(name, options = {}) ⇒ Object
Delegates to Dropbox::API#rename.
65 66 67 68 69 |
# File 'lib/dropbox/entry.rb', line 65 def rename(name, ={}) result = @session.rename(path, name, ) @path = result.path.gsub(/^\//, '') return result end |
#thumbnail(*args) ⇒ Object
Delegates to Dropbox::API#thumbnail.
94 95 96 |
# File 'lib/dropbox/entry.rb', line 94 def thumbnail(*args) @session.thumbnail path, *args end |