Class: Arv::Collection
- Inherits:
-
Object
show all
- Defined in:
- lib/arvados/collection.rb
Defined Under Namespace
Classes: CollectionFile, CollectionItem, CollectionRoot, CollectionStream, LocatorList, LocatorRange, LocatorSegment, StreamManifest
Instance Method Summary
collapse
Constructor Details
#initialize(manifest_text = "") ⇒ Collection
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/arvados/collection.rb', line 5
def initialize(manifest_text="")
@manifest_text = manifest_text
@modified = false
@root = CollectionRoot.new
manifest = Keep::Manifest.new(manifest_text)
manifest.each_line do |stream_root, locators, file_specs|
if stream_root.empty? or locators.empty? or file_specs.empty?
raise ArgumentError.new("manifest text includes malformed line")
end
loc_list = LocatorList.new(locators)
file_specs.map { |s| manifest.split_file_token(s) }.
each do |file_start, file_len, file_path|
begin
@root.file_at(normalize_path(stream_root, file_path)).
add_segment(loc_list.segment(file_start, file_len))
rescue Errno::ENOTDIR, Errno::EISDIR => error
raise ArgumentError.new("%p is both a stream and file" %
error.to_s.partition(" - ").last)
end
end
end
end
|
Instance Method Details
#cp_r(source, target, source_collection = nil) ⇒ Object
46
47
48
49
|
# File 'lib/arvados/collection.rb', line 46
def cp_r(source, target, source_collection=nil)
opts = {descend_target: !source.end_with?("/")}
copy(:merge, source.chomp("/"), target, source_collection, opts)
end
|
#each_file_path(&block) ⇒ Object
51
52
53
|
# File 'lib/arvados/collection.rb', line 51
def each_file_path(&block)
@root.each_file_path(&block)
end
|
#exist?(path) ⇒ Boolean
55
56
57
58
59
60
61
62
|
# File 'lib/arvados/collection.rb', line 55
def exist?(path)
begin
substream, item = find(path)
not (substream.leaf? or substream[item].nil?)
rescue Errno::ENOENT, Errno::ENOTDIR
false
end
end
|
#manifest_text ⇒ Object
28
29
30
|
# File 'lib/arvados/collection.rb', line 28
def manifest_text
@manifest_text ||= @root.manifest_text
end
|
#modified? ⇒ Boolean
32
33
34
|
# File 'lib/arvados/collection.rb', line 32
def modified?
@modified
end
|
#normalize ⇒ Object
41
42
43
44
|
# File 'lib/arvados/collection.rb', line 41
def normalize
@manifest_text = @root.manifest_text
self
end
|
#rename(source, target) ⇒ Object
64
65
66
|
# File 'lib/arvados/collection.rb', line 64
def rename(source, target)
copy(:add_copy, source, target) { rm_r(source) }
end
|
#rm(source) ⇒ Object
68
69
70
|
# File 'lib/arvados/collection.rb', line 68
def rm(source)
remove(source)
end
|
#rm_r(source) ⇒ Object
72
73
74
|
# File 'lib/arvados/collection.rb', line 72
def rm_r(source)
remove(source, recursive: true)
end
|
#unmodified ⇒ Object
36
37
38
39
|
# File 'lib/arvados/collection.rb', line 36
def unmodified
@modified = false
self
end
|