Class: Dropbox::Entry

Inherits:
Object show all
Defined in:
lib/dropbox/entry.rb

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

Instance Method Summary collapse

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

#pathObject (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.



67
68
69
# File 'lib/dropbox/entry.rb', line 67

def copy(dest, options={})
  @session.copy path, dest, options
end

#delete(options = {}) ⇒ Object Also known as: rm

Delegates to Dropbox::API#delete.



74
75
76
# File 'lib/dropbox/entry.rb', line 74

def delete(options={})
  @session.delete path, options
end

#download(options = {}) ⇒ Object Also known as: body

Delegates to Dropbox::API#download.



81
82
83
# File 'lib/dropbox/entry.rb', line 81

def download(options={})
  @session.download path, options
end

#inspectObject

:nodoc:



98
99
100
# File 'lib/dropbox/entry.rb', line 98

def inspect # :nodoc:
  "#<#{self.class.to_s} #{path}>"
end

Delegates to Dropbox::API#link.



94
95
96
# File 'lib/dropbox/entry.rb', line 94

def link(options={})
  @session.link path, options
end

#list(options = {}) ⇒ Object Also known as: ls

Delegates to Dropbox::API#list



43
44
45
# File 'lib/dropbox/entry.rb', line 43

def list(options={})
  @session.list path, options
end

#metadata(options = {}) ⇒ Object Also known as: info

Delegates to Dropbox::API#metadata.



36
37
38
# File 'lib/dropbox/entry.rb', line 36

def (options={})
  @session. path, options
end

#move(dest, options = {}) ⇒ Object Also known as: mv

Delegates to Dropbox::API#move.



50
51
52
53
54
# File 'lib/dropbox/entry.rb', line 50

def move(dest, options={})
  result = @session.move(path, dest, options)
  @path = result.path.gsub(/^\//, '')
  return result
end

#rename(name, options = {}) ⇒ Object

Delegates to Dropbox::API#rename.



59
60
61
62
63
# File 'lib/dropbox/entry.rb', line 59

def rename(name, options={})
  result = @session.rename(path, name, options)
  @path = result.path.gsub(/^\//, '')
  return result
end

#thumbnail(*args) ⇒ Object

Delegates to Dropbox::API#thumbnail.



88
89
90
# File 'lib/dropbox/entry.rb', line 88

def thumbnail(*args)
  @session.thumbnail path, *args
end