lib/box/folder.rb in box-api-0.1.6 vs lib/box/folder.rb in box-api-0.1.7
- old
+ new
@@ -5,10 +5,11 @@
class Folder < Item
attr_accessor :cached_tree
def self.type; 'folder'; end
+ # override the existing info method so that we create empty folders/files first
def info(refresh = false)
return self if @cached_info and not refresh
create_sub_items(nil, Box::Folder)
create_sub_items(nil, Box::File)
@@ -48,11 +49,11 @@
end
# search for items using criteria
def find(criteria)
recursive = criteria.delete(:recursive)
- recursive = true if recursive == nil # default to true
+ recursive = false if recursive == nil # default to false for performance reasons
tree if recursive # get the full tree
find!(criteria, recursive)
end
@@ -101,10 +102,11 @@
@data[item_class.types] << item
end
end
end
+ # update the cached status of all sub items, as we got the entire tree
def force_cached_tree
create_sub_items(nil, Box::Folder)
create_sub_items(nil, Box::File)
files.each do |file|
@@ -117,9 +119,10 @@
folder.force_cached_tree
end
end
+ # search for any files/folders that match the criteria sent
def find!(criteria, recursive)
matches = (files + folders).collect do |item| # search over our files and folders
match = criteria.all? do |key, value| # make sure all criteria pass
item.send(key) == value.to_s rescue false
end