Sha256: d2d2683e9eb77ff52352a4f84b2da775c43af69815e8eb5ced183b838c9033c1

Contents?: true

Size: 1.61 KB

Versions: 65

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require 'avm/data/callbacks'
require 'eac_ruby_utils/core_ext'

module Avm
  module Data
    class Package
      require_sub __FILE__, require_mode: :kernel
      include ::Avm::Data::Callbacks

      DATA_FILE_EXTENSION = '.tar'

      def initialize(options)
        options = options.to_options_consumer
        units = options.consume(:units)
        options.validate
        units.if_present do |v|
          v.each { |identifier, unit| add_unit(identifier, unit) }
        end
      end

      # @return [Avm::Data::Package] Return +self+.
      def add_unit(identifier, unit)
        units[identifier.to_sym] = unit

        self
      end

      # @return [String]
      def data_file_extension
        DATA_FILE_EXTENSION
      end

      def dump_units_to_directory(directory, selected_units = nil)
        run_callbacks :dump do
          (selected_units || units).each do |identifier, unit|
            unit.dump_to_directory(directory, identifier)
          end
        end
      end

      def load_units_from_directory(directory, selected_units = nil)
        run_callbacks :load do
          (selected_units || units).each do |identifier, unit|
            unit.load_from_directory(directory, identifier)
          end
        end
      end

      # @param id [Symbol]
      # @return [Avm::Data::UnitWithCommands]
      def unit(identifier)
        units[identifier.to_sym] || raise("No unit found with identifier \"#{identifier}\"")
      end

      def units
        @units ||= {}
      end

      # @return [Enumerable<String>]
      def units_ids
        units.keys
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 2 rubygems

Version Path
avm-0.94.1 lib/avm/data/package.rb
eac_tools-0.98.0 sub/avm/lib/avm/data/package.rb
avm-0.94.0 lib/avm/data/package.rb
eac_tools-0.94.0 sub/avm/lib/avm/data/package.rb
avm-0.93.0 lib/avm/data/package.rb
eac_tools-0.92.0 sub/avm/lib/avm/data/package.rb
avm-0.92.0 lib/avm/data/package.rb
eac_tools-0.91.0 sub/avm/lib/avm/data/package.rb
avm-0.90.1 lib/avm/data/package.rb
eac_tools-0.87.1 sub/avm/lib/avm/data/package.rb
avm-0.90.0 lib/avm/data/package.rb
eac_tools-0.87.0 sub/avm/lib/avm/data/package.rb
avm-0.89.0 lib/avm/data/package.rb
eac_tools-0.86.12 sub/avm/lib/avm/data/package.rb
avm-0.88.0 lib/avm/data/package.rb
eac_tools-0.86.11 sub/avm/lib/avm/data/package.rb
avm-0.87.0 lib/avm/data/package.rb
eac_tools-0.86.8 sub/avm/lib/avm/data/package.rb
avm-0.86.2 lib/avm/data/package.rb
eac_tools-0.86.7 sub/avm/lib/avm/data/package.rb