Class: ALD::Package::Generator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#definitionObject



11
12
13
14
15
16
17
# File 'lib/ALD/package_generator.rb', line 11

def definition
  if @definition.is_a? ALD::Definition
    @definition
  elsif @definition.is_a? ALD::Definition::Generator
    @definition.generate!
  end
end

Class Method Details

.from_package(package) ⇒ Object



49
50
51
# File 'lib/ALD/package_generator.rb', line 49

def self.from_package(package)
  nil
end

Instance Method Details

#generate!(path) ⇒ Object

Creates a new package file from the given data

generator - an ALD::Package::Generator instance to create the package from path - the path where to create the package. This file must not yet exist.

Returns a new ALD::Package instance representing the newly created file



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ALD/package_generator.rb', line 29

def generate!(path)
  if File.exists? path
    raise IOError, "Destination '#{path}' already exists!"
  end

  raise InvalidPackageError unless valid?

  archive = Zip::File.open(path, Zip::File::CREATE)

  archive.get_output_stream('definition.ald') do |s|
    s << definition.to_s
  end

  files.each do |path, src|
    archive.add(path, src)
  end

  Package.new(file)
end

#valid?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ALD/package_generator.rb', line 19

def valid?
  true && @definition.valid?
end