class ALD::Package

Represents an ALD package file containing an app or library and its definition.

Public

↑ top

Attributes

definition[R]

The ALD::Definition instance representing the definition contained in the package. Use this to extract all the information on the package.

Public Class Methods

new(file) click to toggle source

Opens a new ALD package file.

file

a String representing the path to the file or a Zip::File instance

Returns

Returns a new ALD::Package instance representing the package file

Raises ALD::NoDefinitionError if the package contains no definition file.

Raises ALD::InvalidPackageError if the package is not valid according to its definition.

# File lib/ALD/package.rb, line 27
def initialize(file)
  if file.is_a? Zip::File
    @archive = file
  else
    @archive = Zip::File.open(file)
  end

  def_entry = @archive.find_entry('definition.ald')
  raise NoDefinitionError if def_entry.nil?

  @definition = Definition.new(def_entry.get_input_stream)
  raise InvalidPackageError, 'The given ZIP file is not a valid ALD archive!' unless Package.valid?(@archive, @definition)

  # todo: file access
end
open(file) click to toggle source

Alias for ::new

# File lib/ALD/package.rb, line 53
def self.open(file)
  new(file)
end
valid?(file, definition) click to toggle source

Tests if a given archive is a valid ALD package. Although part of the public API, most library consumers will not need to call it, as it is already called by ::new.

Not yet implemented.

file

a Zip::File instance for the package

definition

an ALD::Definition instance the package must meet

Returns

Returns true if it is valid, false otherwise

# File lib/ALD/package.rb, line 67
def self.valid?(file, definition)
  true # todo
end

Public Instance Methods

close() click to toggle source

Closes a no longer required package. While this method has little effect for now, calling it should be considered best practice and ensures forward-compatibility.

Returns

Returns nothing.

# File lib/ALD/package.rb, line 48
def close
  @archive.close
end

Internal

↑ top

Attributes

archive[R]

The rubyzip Zip::File object containing the data.