Class: HtmlMockup::Release::Finalizers::Zip

Inherits:
Base
  • Object
show all
Defined in:
lib/html_mockup/release/finalizers/zip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from HtmlMockup::Release::Finalizers::Base

Instance Attribute Details

#releaseObject (readonly)

Returns the value of attribute release.



5
6
7
# File 'lib/html_mockup/release/finalizers/zip.rb', line 5

def release
  @release
end

Instance Method Details

#call(release, options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :prefix (Object)

    Prefix to put before the version (default = “html”)

  • :zip (Object)

    The zip command



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
34
35
36
37
38
# File 'lib/html_mockup/release/finalizers/zip.rb', line 9

def call(release, options = {})
  if options
    options = @options.dup.update(options)
  else
    options = @options
  end
  
  options = {
    :zip => "zip",
    :prefix => "html"
  }.update(options)

  name = [options[:prefix], release.scm.version].join("-") + ".zip"
  release.log(self, "Finalizing release to #{release.target_path + name}")
  
  if File.exist?(release.target_path + name)
    release.log(self, "Removing existing target #{release.target_path + name}")
    FileUtils.rm_rf(release.target_path + name)
  end
  
  begin
    `#{options[:zip]} -v`
  rescue Errno::ENOENT
    raise RuntimeError, "Could not find zip in #{options[:zip].inspect}"
  end

  ::Dir.chdir(release.build_path) do
    `#{options[:zip]} -r -9 "#{release.target_path + name}" ./*`
  end
end