Class: ALD::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/ALD/package.rb,
lib/ALD/package_generator.rb

Overview

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

Defined Under Namespace

Classes: Generator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Package

Public: Opens a new ALD package file.

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

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.

Raises:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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

Instance Attribute Details

#archiveObject (readonly)

Internal: The rubyzip Zip::File object containing the data.



11
12
13
# File 'lib/ALD/package.rb', line 11

def archive
  @archive
end

#definitionObject (readonly)

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



15
16
17
# File 'lib/ALD/package.rb', line 15

def definition
  @definition
end

Class Method Details

.open(file) ⇒ Object

Public: Alias for ::new



53
54
55
# File 'lib/ALD/package.rb', line 53

def self.open(file)
  new(file)
end

.valid?(file, definition) ⇒ Boolean

Public: 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 true if it is valid, false otherwise

Returns:

  • (Boolean)


67
68
69
# File 'lib/ALD/package.rb', line 67

def self.valid?(file, definition)
  true # todo
end

Instance Method Details

#closeObject

Public: 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 nothing.



48
49
50
# File 'lib/ALD/package.rb', line 48

def close
  @archive.close
end