class Sluice::Storage::S3::Manifest
Class to read and maintain a manifest.
Attributes
manifest_file[R]
s3_location[R]
scope[R]
Public Class Methods
new(s3_location, scope)
click to toggle source
# File lib/sluice/storage/s3/manifest.rb, line 59 def initialize(s3_location, scope) @s3_location = s3_location @scope = scope @manifest_file = "%ssluice-%s-manifest" % [s3_location.dir_as_path, scope.to_s] nil end
Private Class Methods
get_manifest(s3, s3_location, filename)
click to toggle source
# File lib/sluice/storage/s3/manifest.rb, line 121 def self.get_manifest(s3, s3_location, filename) s3.directories.get(s3_location.bucket, prefix: s3_location.dir).files.get(filename) # TODO: break out into new generic get_file() procedure end
Public Instance Methods
add_entries(s3, entries)
click to toggle source
# File lib/sluice/storage/s3/manifest.rb, line 94 def add_entries(s3, entries) existing = get_entries(s3) filenames = entries.map { |filepath| File.basename(filepath) } # TODO: update when non-filename-based manifests supported all = (existing + filenames) manifest = self.class.get_manifest(s3, @s3_location, @manifest_file) body = all.join("\n") if manifest.nil? bucket = s3.directories.get(s3_location.bucket).files.create( :key => @manifest_file, :body => body ) else manifest.body = body manifest.save end all end
get_entries(s3)
click to toggle source
# File lib/sluice/storage/s3/manifest.rb, line 73 def get_entries(s3) manifest = self.class.get_manifest(s3, @s3_location, @manifest_file) if manifest.nil? return [] end manifest.body.split("\n").reject(&:empty?) end