Class: Owlet::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/owlet/package.rb

Class Method Summary collapse

Class Method Details

.create(args = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/owlet/package.rb', line 6

def self.create(args = {})
  source = args[:source]
  
  # Validate source
  unless File.directory?(source)
    raise "Invalid source directory."
  end
  
  ext = File.extname(source)
  dest_ext = case ext[1..-1]
  when "alulaextension"
    "alulaextz"
  when "alulatheme"
    "alulathmz"
  else
    raise "Unknown owlet type."
  end
  destination = args[:destination] || File.join(File.dirname(source), "#{File.basename(source, ext)}.#{dest_ext}")
  
  Zip::ZipFile.open(destination, Zip::ZipFile::CREATE) do |zip|
    Dir.glob("#{source}/**/*").each do |entry|
      zip.add(entry.gsub("#{source}/", ''), entry)
    end
  end
  
  # All done
  return destination
end