I have two classes in my REST API wrapeer: Wrapper::Folder and Wrapper::File. Each folder can contain numerous folders and files. The contents of folder can be retrived by .list. class method.
I want to implement .all class method for Wrapper::File which would return an array of all files in all folders.
The following method doesn’t work but shows something like I want.
class Wrapper::File
def self.all
folders = Wrapper::Folder.list('/')
files = []
while folders.size > 0
folders.each do |object|
if object.is_a?(Wrapper::Folder)
folders = Wrapper::Folder.list('/')
else
files << object
end
end
end
end
end
Untested, but this would be the basic gist of the recursive solution. Would return an array of file names (with paths) and without directories.