Class: Avm::Data::Package

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/avm/data/package.rb,
lib/avm/data/package/dump.rb,
lib/avm/data/package/load.rb,
lib/avm/data/package/clear.rb,
lib/avm/data/package/base_performer.rb,
lib/avm/data/package/build_directory.rb

Direct Known Subclasses

Instances::Data::Package

Defined Under Namespace

Modules: BuildDirectory Classes: BasePerformer, Clear, Dump, Load

Constant Summary collapse

DATA_FILE_EXTENSION =
'.tar'

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Package

Returns a new instance of Package.



14
15
16
17
18
19
20
21
# File 'lib/avm/data/package.rb', line 14

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

Instance Method Details

#add_unit(identifier, unit) ⇒ Avm::Data::Package

Return self.

Returns:



24
25
26
27
28
# File 'lib/avm/data/package.rb', line 24

def add_unit(identifier, unit)
  units[identifier.to_sym] = unit

  self
end

#data_file_extensionString

Returns:

  • (String)


31
32
33
# File 'lib/avm/data/package.rb', line 31

def data_file_extension
  DATA_FILE_EXTENSION
end

#dump_units_to_directory(directory, selected_units = nil) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/avm/data/package.rb', line 39

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

#load(data_path) ⇒ Object



35
36
37
# File 'lib/avm/data/package.rb', line 35

def load(data_path)
  ::Avm::Data::Package::Load.new(self, data_path)
end

#load_units_from_directory(directory) ⇒ Object



47
48
49
50
51
# File 'lib/avm/data/package.rb', line 47

def load_units_from_directory(directory)
  run_callbacks :load do
    units.each { |identifier, unit| unit.load_from_directory(directory, identifier) }
  end
end

#unit(identifier) ⇒ Avm::Data::UnitWithCommands

Parameters:

  • id (Symbol)

Returns:



55
56
57
# File 'lib/avm/data/package.rb', line 55

def unit(identifier)
  units[identifier.to_sym] || raise("No unit found with identifier \"#{identifier}\"")
end

#unitsObject



59
60
61
# File 'lib/avm/data/package.rb', line 59

def units
  @units ||= {}
end

#units_idsEnumerable<String>

Returns:

  • (Enumerable<String>)


64
65
66
# File 'lib/avm/data/package.rb', line 64

def units_ids
  units.keys
end