Sha256: bbb21a83c57ac771dce9c37e9c2556756497f905f82add8f91381ef5364d5c1c

Contents?: true

Size: 899 Bytes

Versions: 10

Compression:

Stored size: 899 Bytes

Contents

require 'fileutils'
require 'uuid'

module PushmiPullyu::AIP
  class EntityInvalid < StandardError; end
  module_function

  def create(entity)
    raise EntityInvalid if entity.blank? ||
                           UUID.validate(entity[:uuid]).blank? ||
                           entity[:type].blank?

    aip_directory = "#{PushmiPullyu.options[:workdir]}/#{entity[:uuid]}"
    aip_filename = "#{aip_directory}.tar"
    begin
      PushmiPullyu::AIP::Downloader.new(entity, aip_directory).run
      PushmiPullyu::AIP::Creator.new(entity[:uuid], aip_directory, aip_filename).run

      yield aip_filename, aip_directory
    # Here we will ensure the files are removed even if an exception comes up.
    # You will notice there is no rescue block.  We will catch exceptions in `PushmiPullyu::CLI`
    ensure
      FileUtils.rm_rf(aip_filename)
      FileUtils.rm_rf(aip_directory)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pushmi_pullyu-2.1.6 lib/pushmi_pullyu/aip.rb
pushmi_pullyu-2.1.5 lib/pushmi_pullyu/aip.rb
pushmi_pullyu-2.1.4 lib/pushmi_pullyu/aip.rb
pushmi_pullyu-2.1.3 lib/pushmi_pullyu/aip.rb
pushmi_pullyu-2.1.2 lib/pushmi_pullyu/aip.rb
pushmi_pullyu-2.1.1 lib/pushmi_pullyu/aip.rb
pushmi_pullyu-2.0.7 lib/pushmi_pullyu/aip.rb
pushmi_pullyu-2.0.6 lib/pushmi_pullyu/aip.rb
pushmi_pullyu-2.0.5 lib/pushmi_pullyu/aip.rb
pushmi_pullyu-2.0.4 lib/pushmi_pullyu/aip.rb