Class: Swaggerless::Packager

Inherits:
Object
  • Object
show all
Defined in:
lib/swaggerless/packager.rb

Instance Method Summary collapse

Constructor Details

#initialize(input_dir, output_file) ⇒ Packager



8
9
10
11
# File 'lib/swaggerless/packager.rb', line 8

def initialize(input_dir, output_file)
  @input_dir = File.expand_path(input_dir);
  @output_file = File.expand_path(output_file);
end

Instance Method Details

#writeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/swaggerless/packager.rb', line 13

def write
  version_hash = version_hash()

  zip_succeeded = false;
  Dir.chdir(@input_dir) do
    # There seems to be a bug that I can't hunt down. Binary files don't package well, therefore falling back to
    # sytem zip - it does the job better. Will fix this in the future.
    zip_succeeded = system("zip -r #{@output_file}_#{version_hash}.zip * > /dev/null");
  end

  if !zip_succeeded then
    puts "Falling back to own implementation of packaging"
    entries = Dir.entries(@input_dir) - %w(. ..)

    ::Zip::File.open("#{@output_file}_#{version_hash}.zip", ::Zip::File::CREATE) do |io|
      write_entries entries, '', io
    end
  end
end