class PushmiPullyu::AIP::Creator

Public Class Methods

new(noid, aip_directory, aip_filename) click to toggle source

Assumption: the AIP has already been downloaded

# File lib/pushmi_pullyu/aip/creator.rb, line 11
def initialize(noid, aip_directory, aip_filename)
  @noid = noid
  @aip_directory = aip_directory
  @aip_filename = aip_filename
end

Public Instance Methods

run() click to toggle source
# File lib/pushmi_pullyu/aip/creator.rb, line 17
def run
  bag_aip
  tar_bag
end

Private Instance Methods

bag_aip() click to toggle source
# File lib/pushmi_pullyu/aip/creator.rb, line 24
def bag_aip
  bag = BagIt::Bag.new(@aip_directory, bag_metadata)
  bag.manifest!
  raise BagInvalid unless bag.valid?
end
bag_metadata() click to toggle source
# File lib/pushmi_pullyu/aip/creator.rb, line 30
def bag_metadata
  { 'AIP-Version' => PushmiPullyu.options[:aip_version] }
end
tar_bag() click to toggle source
# File lib/pushmi_pullyu/aip/creator.rb, line 34
def tar_bag
  # We want to change the directory to the work directory path so we get the tar file to be exactly
  # the contents of the noid directory and not the entire work directory structure. For example the noid.tar
  # contains just the noid directory instead of having the noid.tar contain the tmp directory
  # which contains the workdir directory and then finally the noid directory

  # Before we change directorys, we need to calculate the absolute filepath of our aip filename
  tar_aip_filename = File.expand_path(@aip_filename)

  Dir.chdir(PushmiPullyu.options[:workdir]) do
    Minitar.pack(@noid, File.open(tar_aip_filename, 'wb'))
  end
end