Sha256: 15acf84603534df0eaa1dab28fc8cd960d240c0781d77d3629a26738199b37ec

Contents?: true

Size: 1.02 KB

Versions: 113

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'minitar'

module Avm
  module Data
    class Package
      class Load
        enable_console_speaker

        attr_reader :package, :data_file_path

        def initialize(package, data_file_path)
          @package = package
          @data_file_path = data_file_path
        end

        def runnable?
          cannot_run_reason.blank?
        end

        def cannot_run_reason
          return nil if data_file_exist?

          "Data file \"#{data_file_path}\" does not exist"
        end

        def run
          raise "Cannot run: #{cannot_run_reason}" unless runnable?

          build_dir = extract_packages_to_build_directory
          package.load_units_from_directory(build_dir)
        end

        def data_file_exist?
          ::File.exist?(data_file_path)
        end

        def extract_packages_to_build_directory
          dir = ::Dir.mktmpdir
          ::Minitar.unpack(data_file_path, dir)
          dir
        end
      end
    end
  end
end

Version data entries

113 entries across 113 versions & 1 rubygems

Version Path
avm-tools-0.58.1 lib/avm/data/package/load.rb
avm-tools-0.58.0 lib/avm/data/package/load.rb
avm-tools-0.57.0 lib/avm/data/package/load.rb
avm-tools-0.56.0 lib/avm/data/package/load.rb
avm-tools-0.55.0 lib/avm/data/package/load.rb
avm-tools-0.54.2 lib/avm/data/package/load.rb
avm-tools-0.54.1 lib/avm/data/package/load.rb
avm-tools-0.54.0 lib/avm/data/package/load.rb
avm-tools-0.53.0 lib/avm/data/package/load.rb
avm-tools-0.52.0 lib/avm/data/package/load.rb
avm-tools-0.51.0 lib/avm/data/package/load.rb
avm-tools-0.50.0 lib/avm/data/package/load.rb
avm-tools-0.49.0 lib/avm/data/package/load.rb
avm-tools-0.48.0 lib/avm/data/package/load.rb
avm-tools-0.47.0 lib/avm/data/package/load.rb
avm-tools-0.46.0 lib/avm/data/package/load.rb
avm-tools-0.45.0 lib/avm/data/package/load.rb
avm-tools-0.44.2 lib/avm/data/package/load.rb
avm-tools-0.44.1 lib/avm/data/package/load.rb
avm-tools-0.44.0 lib/avm/data/package/load.rb