Class: Arv::Collection
- Inherits:
-
Object
show all
- Defined in:
- lib/arvados/collection.rb
Defined Under Namespace
Classes: CollectionFile, CollectionItem, CollectionRoot, CollectionStream, LocatorList, LocatorRange, StreamManifest
Instance Method Summary
collapse
Constructor Details
#initialize(manifest_text = "") ⇒ Collection
Returns a new instance of Collection.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/arvados/collection.rb', line 9
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
50
51
52
53
|
# File 'lib/arvados/collection.rb', line 50
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
55
56
57
|
# File 'lib/arvados/collection.rb', line 55
def each_file_path(&block)
@root.each_file_path(&block)
end
|
#exist?(path) ⇒ Boolean
59
60
61
62
63
64
65
66
|
# File 'lib/arvados/collection.rb', line 59
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
32
33
34
|
# File 'lib/arvados/collection.rb', line 32
def manifest_text
@manifest_text ||= @root.manifest_text
end
|
#modified? ⇒ Boolean
36
37
38
|
# File 'lib/arvados/collection.rb', line 36
def modified?
@modified
end
|
#normalize ⇒ Object
45
46
47
48
|
# File 'lib/arvados/collection.rb', line 45
def normalize
@manifest_text = @root.manifest_text
self
end
|
#rename(source, target) ⇒ Object
68
69
70
|
# File 'lib/arvados/collection.rb', line 68
def rename(source, target)
copy(:add_copy, source, target) { rm_r(source) }
end
|
#rm(source) ⇒ Object
72
73
74
|
# File 'lib/arvados/collection.rb', line 72
def rm(source)
remove(source)
end
|
#rm_r(source) ⇒ Object
76
77
78
|
# File 'lib/arvados/collection.rb', line 76
def rm_r(source)
remove(source, :recursive => true)
end
|
#unmodified ⇒ Object
40
41
42
43
|
# File 'lib/arvados/collection.rb', line 40
def unmodified
@modified = false
self
end
|