Class: Duracloud::Manifest
- Inherits:
-
Object
- Object
- Duracloud::Manifest
- Includes:
- TSV
- Defined in:
- lib/duracloud/manifest.rb
Constant Summary collapse
- TSV_FORMAT =
"TSV"
- BAGIT_FORMAT =
"BAGIT"
- MAX_TRIES =
120
- RETRY_SLEEP =
10
Constants included from TSV
Instance Attribute Summary collapse
-
#space_id ⇒ Object
readonly
Returns the value of attribute space_id.
-
#store_id ⇒ Object
readonly
Returns the value of attribute store_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#bagit {|String| ... } ⇒ Duracloud::Response
Downloads the manifest in BAGIT format.
-
#download(format: TSV_FORMAT) {|String| ... } ⇒ Duracloud::Response, String
Downloads the manifest.
-
#download_generated(format: TSV_FORMAT, max_tries: MAX_TRIES, retry_sleep: RETRY_SLEEP) {|String| ... } ⇒ Object
Downloads the generated manifest.
-
#generate(format: TSV_FORMAT) ⇒ String
Request the manifest for the space to be generated.
-
#initialize(space_id, store_id = nil) ⇒ Manifest
constructor
A new instance of Manifest.
-
#tsv {|String| ... } ⇒ Duracloud::Response, ...
Returns the manifest in TSV format, downloading from DuraCloud is not pre-loaded.
Methods included from TSV
#csv, #load_tsv, #load_tsv_file, #rows, #table, #to_s, #tsv_source, #tsv_source?
Constructor Details
#initialize(space_id, store_id = nil) ⇒ Manifest
Returns a new instance of Manifest.
24 25 26 27 |
# File 'lib/duracloud/manifest.rb', line 24 def initialize(space_id, store_id = nil) @space_id = space_id @store_id = store_id end |
Instance Attribute Details
#space_id ⇒ Object (readonly)
Returns the value of attribute space_id.
14 15 16 |
# File 'lib/duracloud/manifest.rb', line 14 def space_id @space_id end |
#store_id ⇒ Object (readonly)
Returns the value of attribute store_id.
14 15 16 |
# File 'lib/duracloud/manifest.rb', line 14 def store_id @store_id end |
Class Method Details
.download(*args, **kwargs, &block) ⇒ Object
16 17 18 |
# File 'lib/duracloud/manifest.rb', line 16 def self.download(*args, **kwargs, &block) new(*args).download(**kwargs, &block) end |
.download_generated(*args, **kwargs, &block) ⇒ Object
20 21 22 |
# File 'lib/duracloud/manifest.rb', line 20 def self.download_generated(*args, **kwargs, &block) new(*args).download_generated(**kwargs, &block) end |
Instance Method Details
#bagit {|String| ... } ⇒ Duracloud::Response
Downloads the manifest in BAGIT format.
43 44 45 |
# File 'lib/duracloud/manifest.rb', line 43 def bagit(&block) download(BAGIT_FORMAT, &block) end |
#download(format: TSV_FORMAT) {|String| ... } ⇒ Duracloud::Response, String
format parameter changed from positional to keyword argument in v0.5.0.
Downloads the manifest
92 93 94 95 96 97 98 99 |
# File 'lib/duracloud/manifest.rb', line 92 def download(format: TSV_FORMAT, &block) fmt = format.to_s.upcase if block_given? get_response(fmt, &block) else get_response(fmt).body end end |
#download_generated(format: TSV_FORMAT, max_tries: MAX_TRIES, retry_sleep: RETRY_SLEEP) {|String| ... } ⇒ Object
Downloads the generated manifest
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/duracloud/manifest.rb', line 68 def download_generated(format: TSV_FORMAT, max_tries: MAX_TRIES, retry_sleep: RETRY_SLEEP, &block) url = generate(format: format) check_generated(url, max_tries, retry_sleep) Tempfile.open(["download", ".gz"], encoding: "ascii-8bit") do |gz_file| client.execute(Request, :get, url) do |chunk| gz_file.write(chunk) end gz_file.close Zlib::GzipReader.open(gz_file.path) do |unzipped| unzipped.each { |line| yield(line) } end end url end |
#generate(format: TSV_FORMAT) ⇒ String
format parameter changed from positional to keyword argument in v0.5.0.
Request the manifest for the space to be generated.
54 55 56 57 58 |
# File 'lib/duracloud/manifest.rb', line 54 def generate(format: TSV_FORMAT) fmt = format.to_s.upcase response = Client.generate_manifest(space_id, query(fmt)) response.header["Location"].first end |
#tsv {|String| ... } ⇒ Duracloud::Response, ...
Returns the manifest in TSV format,
downloading from DuraCloud is not pre-loaded.
35 36 37 |
# File 'lib/duracloud/manifest.rb', line 35 def tsv(&block) tsv_source? ? super : download(TSV_FORMAT, &block) end |