app/models/jail/cdnjs.rb in jail-0.1.1 vs app/models/jail/cdnjs.rb in jail-0.2.0
- old
+ new
@@ -42,23 +42,40 @@
# gets the version from the package.json & returns a path
def version_path
Pathname(root_path).join(version)
end
- def files
- @files ||= github.where(version_path).contents
+ def version_files
+ @version_files ||= github.where(version_path).contents
end
- def file(name)
- github.where(version_path.join(name))
+ # build a depth first tree
+ def tree
+ @tree and return @tree
+ @tree = []
+ file_set = version_files
+
+ while child = file_set.shift
+ tree << child #if child.dir?
+
+ if child.type == "dir"
+ file_set.unshift( github.where(child.path).contents ).flatten!
+ end
+ end
+
+ @tree
end
+ def file(path)
+ github.where(path)
+ end
+
def mapped_files
files.map(&:name).group_by {|name| Pathname(name).extname }
end
def install(params)
- files_to_write = params.map {|file, num| file if num == "1"}.compact!
+ files_to_write = params.map {|file, checkbox_val| file if checkbox_val == "1"}.compact
files_to_write.each do |name|
file(name).download()
end
end