1 class Collection < ArvadosBase
2 MD5_EMPTY = 'd41d8cd98f00b204e9800998ecf8427e'
5 if Collection.is_empty_blob_locator? self.uuid
12 # Return true if the given string is the locator of a zero-length blob
13 def self.is_empty_blob_locator? locator
14 !!locator.to_s.match("^#{MD5_EMPTY}(\\+.*)?\$")
17 def self.goes_in_projects?
22 ApplicationController.helpers.human_readable_bytes_html(total_bytes) + " " + super
38 return [] if files.empty?
39 tree = files.group_by { |file_spec| File.split(file_spec.first) }
40 # Fill in entries for empty directories.
41 tree.keys.map { |basedir, _| File.split(basedir) }.each do |splitdir|
42 until tree.include?(splitdir)
44 splitdir = File.split(splitdir.first)
47 dir_to_tree = lambda do |dirname|
48 # First list subdirectories, with their files inside.
49 subnodes = tree.keys.select { |bd, td| (bd == dirname) and (td != '.') }
50 .sort.flat_map do |parts|
51 [parts + [nil]] + dir_to_tree.call(File.join(parts))
53 # Then extend that list with files in this directory.
54 subnodes + tree[File.split(dirname)]
59 def attribute_editable? attr, *args
60 if %w(name description manifest_text).include? attr.to_s
72 arvados_api_client.api "collections/#{self.uuid}/", "provenance"
76 arvados_api_client.api "collections/#{self.uuid}/", "used_by"
81 return self[:portable_data_hash]
87 def portable_data_hash
88 if self[:portable_data_hash].nil?
95 def friendly_link_name
96 if self.respond_to? :name
99 self.portable_data_hash