Class: BuildpackSupport::Rake::PackageZipTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- BuildpackSupport::Rake::PackageZipTask
- Defined in:
- lib/buildpack_support/rake/package_zip_task.rb
Overview
A task generator for the task that creates the package zip file.
Instance Attribute Summary collapse
-
#package_name ⇒ String
The name of the package.
-
#staging_dir ⇒ String
The directory to zip the contents of.
-
#verbose ⇒ Boolean
The verbosity of the task.
Instance Method Summary collapse
-
#initialize(&task_block) ⇒ PackageZipTask
constructor
A new instance of PackageZipTask.
-
#run_task(name, staging_dir, verbose) ⇒ void
Runs the task.
Constructor Details
#initialize(&task_block) ⇒ PackageZipTask
Returns a new instance of PackageZipTask.
39 40 41 42 43 44 45 46 47 |
# File 'lib/buildpack_support/rake/package_zip_task.rb', line 39 def initialize(&task_block) @verbose = false task_block.call(*[self].slice(0, task_block.arity)) if task_block abort 'package_name must be configured' unless package_name abort 'staging_dir must be configured' unless staging_dir task(package_name) { |t| run_task t.name, staging_dir, verbose } end |
Instance Attribute Details
#package_name ⇒ String
Returns the name of the package.
29 30 31 |
# File 'lib/buildpack_support/rake/package_zip_task.rb', line 29 def package_name @package_name end |
#staging_dir ⇒ String
Returns the directory to zip the contents of.
33 34 35 |
# File 'lib/buildpack_support/rake/package_zip_task.rb', line 33 def staging_dir @staging_dir end |
#verbose ⇒ Boolean
Returns the verbosity of the task. Defaults to true
.
37 38 39 |
# File 'lib/buildpack_support/rake/package_zip_task.rb', line 37 def verbose @verbose end |
Instance Method Details
#run_task(name, staging_dir, verbose) ⇒ void
This method returns an undefined value.
Runs the task
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/buildpack_support/rake/package_zip_task.rb', line 55 def run_task(name, staging_dir, verbose) RakeFileUtils.verbose(verbose) do mkdir_p File.dirname(name) Zip::File.open(name, Zip::File::CREATE) do |zipfile| Dir[File.join(staging_dir, '**', '**')].each do |file| relative_path = relative_path(file, staging_dir) "a #{relative_path}" if verbose zipfile.add(relative_path, file) end end end "Created package #{name}" end |