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.98.0 lib/avm/data/package/load.rb
avm-tools-0.97.0 lib/avm/data/package/load.rb
avm-tools-0.96.0 lib/avm/data/package/load.rb
avm-tools-0.95.0 lib/avm/data/package/load.rb
avm-tools-0.94.3 lib/avm/data/package/load.rb
avm-tools-0.94.2 lib/avm/data/package/load.rb
avm-tools-0.94.1 lib/avm/data/package/load.rb
avm-tools-0.94.0 lib/avm/data/package/load.rb
avm-tools-0.93.0 lib/avm/data/package/load.rb
avm-tools-0.92.0 lib/avm/data/package/load.rb
avm-tools-0.91.0 lib/avm/data/package/load.rb
avm-tools-0.90.0 lib/avm/data/package/load.rb
avm-tools-0.89.0 lib/avm/data/package/load.rb
avm-tools-0.88.0 lib/avm/data/package/load.rb
avm-tools-0.87.1 lib/avm/data/package/load.rb
avm-tools-0.87.0 lib/avm/data/package/load.rb
avm-tools-0.86.0 lib/avm/data/package/load.rb
avm-tools-0.85.1 lib/avm/data/package/load.rb
avm-tools-0.85.0 lib/avm/data/package/load.rb
avm-tools-0.84.0 lib/avm/data/package/load.rb