Sha256: 8bf697928bccaf8d7ac62598772dd3b1999d774de0d56962620c1fb631ad9c85

Contents?: true

Size: 1.16 KB

Versions: 8

Compression:

Stored size: 1.16 KB

Contents

require 'minitar'
require 'bagit'
require 'fileutils'

class PushmiPullyu::AIP::Creator

  class BagInvalid < StandardError; end

  # Assumption: the AIP has already been downloaded

  def initialize(noid, aip_directory, aip_filename)
    @noid = noid
    @aip_directory = aip_directory
    @aip_filename = aip_filename
  end

  def run
    bag_aip
    tar_bag
  end

  private

  def bag_aip
    bag = BagIt::Bag.new(@aip_directory)
    bag.manifest!
    raise BagInvalid unless bag.valid?
  end

  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

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pushmi_pullyu-0.2.7 lib/pushmi_pullyu/aip/creator.rb
pushmi_pullyu-0.2.6 lib/pushmi_pullyu/aip/creator.rb
pushmi_pullyu-0.2.5 lib/pushmi_pullyu/aip/creator.rb
pushmi_pullyu-0.2.4 lib/pushmi_pullyu/aip/creator.rb
pushmi_pullyu-0.2.3 lib/pushmi_pullyu/aip/creator.rb
pushmi_pullyu-0.2.2 lib/pushmi_pullyu/aip/creator.rb
pushmi_pullyu-0.2.1 lib/pushmi_pullyu/aip/creator.rb
pushmi_pullyu-0.2.0 lib/pushmi_pullyu/aip/creator.rb