Class: BuildpackSupport::Rake::WriteVersionFileTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/buildpack_support/rake/write_version_file_task.rb

Overview

A task generator for the task that creates version file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&task_block) ⇒ WriteVersionFileTask

Creates an instance



44
45
46
47
48
49
50
51
52
53
# File 'lib/buildpack_support/rake/write_version_file_task.rb', line 44

def initialize(&task_block)
  @verbose = false

  task_block.call(*[self].slice(0, task_block.arity)) if task_block
  abort 'buildpack_version must be configured' unless buildpack_version
  abort 'package_name must be configured' unless package_name
  abort 'staging_dir must be configured' unless staging_dir

  create_task buildpack_version, package_name, staging_dir, verbose
end

Instance Attribute Details

#buildpack_versionBuildpackSupport::BuildpackVersion

Returns the version of the buildpack.

Returns:



29
30
31
# File 'lib/buildpack_support/rake/write_version_file_task.rb', line 29

def buildpack_version
  @buildpack_version
end

#package_nameString

Returns the name of the package.

Returns:

  • (String)

    the name of the package



33
34
35
# File 'lib/buildpack_support/rake/write_version_file_task.rb', line 33

def package_name
  @package_name
end

#staging_dirString

Returns the directory to zip the contents of.

Returns:

  • (String)

    the directory to zip the contents of.



37
38
39
# File 'lib/buildpack_support/rake/write_version_file_task.rb', line 37

def staging_dir
  @staging_dir
end

#verboseBoolean

Returns the verbosity of the task. Defaults to false.

Returns:

  • (Boolean)

    the verbosity of the task. Defaults to false.



41
42
43
# File 'lib/buildpack_support/rake/write_version_file_task.rb', line 41

def verbose
  @verbose
end

Instance Method Details

#run_task(name, buildpack_version, verbose) ⇒ void

This method returns an undefined value.

Runs the task

Parameters:

  • name (String)

    the file to write to

  • buildpack_version (BuildpackSupport::BuildpackVersion)

    the buildpack version to write to the file

  • verbose (Boolean)

    whether to print messages to the console



61
62
63
64
65
# File 'lib/buildpack_support/rake/write_version_file_task.rb', line 61

def run_task(name, buildpack_version, verbose)
  RakeFileUtils.verbose(verbose) { mkdir_p File.dirname(name) }
  File.open(name, 'w') { |f| f.write(buildpack_version.to_hash.to_yaml) }
  rake_output_message "Wrote buildpack version to #{name}" if verbose
end