Class: Box::File

Inherits:
Item
  • Object
show all
Defined in:
lib/box/file.rb

Overview

Represents a file stored on Box. Any attributes or actions typical to a Box file can be accessed through this class.

Instance Attribute Summary

Attributes inherited from Item

#api, #data, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Item

#copy, #delete, #description, #force_cached_info, #id, #info, #initialize, #method_missing, #move, #path, #rename, #type, #types, types

Constructor Details

This class inherits a constructor from Box::Item

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Box::Item

Class Method Details

.typeString

Returns The string representation of this item.

Returns:

  • (String)

    The string representation of this item.



9
# File 'lib/box/file.rb', line 9

def self.type; 'file'; end

Instance Method Details

#download(path) ⇒ Object

Download this file to the specified path.

Parameters:

  • path (String)

    The path to write the file.



14
15
16
# File 'lib/box/file.rb', line 14

def download(path)
  @api.download(path, id)
end

#upload_copy(path) ⇒ File

Upload a new copy of this file. The name will be “file (#).ext” for the each additional copy.

Parameters:

  • path (String)

    The path to the file to upload.

Returns:

  • (File)

    The newly created file.



36
37
38
39
40
41
# File 'lib/box/file.rb', line 36

def upload_copy(path)
  info = @api.new_copy(path, id)['files']['file']
  parent.delete_info('files')

  self.class.new(api, parent, info)
end

#upload_overwrite(path) ⇒ File

Overwrite this file, using the file at the specified path

Parameters:

  • path (String)

    The path to the file to upload.

Returns:



22
23
24
25
26
27
28
29
# File 'lib/box/file.rb', line 22

def upload_overwrite(path)
  info = @api.overwrite(path, id)['files']['file']

  clear_info
  update_info(info)

  self
end