Class: Sluice::Storage::S3::Manifest

Inherits:
Object
  • Object
show all
Includes:
Contracts
Defined in:
lib/sluice/storage/s3/manifest.rb

Overview

Class to read and maintain a manifest.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s3_location, scope) ⇒ Manifest

Returns a new instance of Manifest.



61
62
63
64
65
66
# File 'lib/sluice/storage/s3/manifest.rb', line 61

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

Instance Attribute Details

#manifest_fileObject (readonly)

Returns the value of attribute manifest_file.



50
51
52
# File 'lib/sluice/storage/s3/manifest.rb', line 50

def manifest_file
  @manifest_file
end

#s3_locationObject (readonly)

Returns the value of attribute s3_location.



50
51
52
# File 'lib/sluice/storage/s3/manifest.rb', line 50

def s3_location
  @s3_location
end

#scopeObject (readonly)

Returns the value of attribute scope.



50
51
52
# File 'lib/sluice/storage/s3/manifest.rb', line 50

def scope
  @scope
end

Instance Method Details

#add_entries(s3, entries) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/sluice/storage/s3/manifest.rb', line 96

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) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/sluice/storage/s3/manifest.rb', line 75

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