Class: BackItUp::FilePackager

Inherits:
Object
  • Object
show all
Defined in:
lib/back_it_up/file_packager.rb

Constant Summary collapse

INVALID_CONFIG_MSG =
"Invalid config"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ FilePackager

Returns a new instance of FilePackager.

Raises:



9
10
11
12
# File 'lib/back_it_up/file_packager.rb', line 9

def initialize(config) 
  raise INVALID_CONFIG_MSG if config == nil || !config.is_a?(Config)
  @config = config
end

Instance Attribute Details

#produced_fileObject (readonly)

Returns the value of attribute produced_file.



7
8
9
# File 'lib/back_it_up/file_packager.rb', line 7

def produced_file
  @produced_file
end

Instance Method Details

#packageObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/back_it_up/file_packager.rb', line 14

def package
  target_filename = create_target_filename
  
  prefix = File.basename(target_filename, ".zip")
  
  Zip::ZipFile.open(target_filename, Zip::ZipFile::CREATE) do |zip|
    @config.files.each do |filename|
      zip.add("./#{prefix}#{filename}", filename)
    end
  end
  
  @produced_file = target_filename
end