Class: Box::Folder
Overview
Represents a folder stored on Box. Any attributes or actions typical to a Box folder can be accessed through this class.
Instance Attribute Summary
Attributes inherited from Item
Class Method Summary collapse
-
.type ⇒ String
The string representation of this item.
Instance Method Summary collapse
-
#create(name, share = 0) ⇒ Folder
Create a new folder using this folder as the parent.
-
#find(criteria) ⇒ Array
Search for sub-items using criteria.
-
#force_cached_info ⇒ Object
Consider the item cached.
-
#force_cached_tree ⇒ Object
Consider the tree cached.
-
#info(refresh = false) ⇒ Item
Get the info for this item.
-
#tree(refresh = false) ⇒ Folder
Get the tree for this folder.
-
#upload(path) ⇒ File
Upload a new file using this folder as the parent.
Methods inherited from Item
#copy, #delete, #description, #id, #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
.type ⇒ String
Returns The string representation of this item.
10 |
# File 'lib/box/folder.rb', line 10 def self.type; 'folder'; end |
Instance Method Details
#create(name, share = 0) ⇒ Folder
Create a new folder using this folder as the parent.
52 53 54 55 56 57 58 |
# File 'lib/box/folder.rb', line 52 def create(name, share = 0) info = @api.create_folder(id, name, share)['folder'] delete_info('folders') Box::Folder.new(api, self, info) end |
#find(criteria) ⇒ Array
The recursive option will call #tree, which can be slow for large folders.
Any item method (as a symbol) can be used as criteria, which could cause major problems if used improperly.
Search for sub-items using criteria.
TODO: Lookup YARD syntax for options hash.
95 96 97 98 99 100 101 102 |
# File 'lib/box/folder.rb', line 95 def find(criteria) recursive = criteria.delete(:recursive) recursive = false if recursive == nil # default to false for performance reasons tree if recursive # get the full tree find!(criteria, recursive) end |
#force_cached_info ⇒ Object
Consider the item cached. This prevents an additional api when we know the item is fully fetched.
105 106 107 108 109 110 |
# File 'lib/box/folder.rb', line 105 def force_cached_info create_sub_items(nil, Box::Folder) create_sub_items(nil, Box::File) super end |
#force_cached_tree ⇒ Object
Consider the tree cached. This prevents an additional api when we know the item is fully fetched.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/box/folder.rb', line 114 def force_cached_tree @cached_tree = true create_sub_items(nil, Box::Folder) create_sub_items(nil, Box::File) folders.each do |folder| folder.force_cached_tree end end |
#info(refresh = false) ⇒ Item
Get the info for this item. Uses a cached copy if avaliable, or else it is fetched from the api.
Files and folders will only be one-level deep, and #tree should be used if fetching deeper than that.
15 16 17 18 19 20 21 22 |
# File 'lib/box/folder.rb', line 15 def info(refresh = false) return self if @cached_info and not refresh create_sub_items(nil, Box::Folder) create_sub_items(nil, Box::File) super end |
#tree(refresh = false) ⇒ Folder
Get the tree for this folder. The tree includes all sub folders and files, including their info. Uses a cached copy if avaliable, or else it is fetched from the api.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/box/folder.rb', line 34 def tree(refresh = false) return self if @cached_tree and not refresh @cached_info = true # count the info as cached as well @cached_tree = true update_info(get_tree) force_cached_tree self end |