Class: BuildpackSupport::Rake::DisableRemoteDownloadsTask

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

Overview

A task generator for the task that disables remote downloads

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&task_block) ⇒ DisableRemoteDownloadsTask

Returns a new instance of DisableRemoteDownloadsTask.



38
39
40
41
42
43
44
45
46
# File 'lib/buildpack_support/rake/disable_remote_downloads_task.rb', line 38

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

  create_task package_name, staging_dir, verbose
end

Instance Attribute Details

#package_nameString

Returns the name of the package.

Returns:

  • (String)

    the name of the package



28
29
30
# File 'lib/buildpack_support/rake/disable_remote_downloads_task.rb', line 28

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



32
33
34
# File 'lib/buildpack_support/rake/disable_remote_downloads_task.rb', line 32

def staging_dir
  @staging_dir
end

#verboseBoolean

Returns the verbosity of the task. Defaults to true.

Returns:

  • (Boolean)

    the verbosity of the task. Defaults to true.



36
37
38
# File 'lib/buildpack_support/rake/disable_remote_downloads_task.rb', line 36

def verbose
  @verbose
end

Instance Method Details

#run_task(source, target, verbose) ⇒ void

This method returns an undefined value.

Runs the task

Parameters:

  • source (String)

    the name of the file to read from

  • target (String)

    the name of the file to write to

  • verbose (Boolean)

    whether to print messages to the console



54
55
56
57
58
59
60
61
62
# File 'lib/buildpack_support/rake/disable_remote_downloads_task.rb', line 54

def run_task(source, target, verbose)
  RakeFileUtils.verbose(verbose) do
    mkdir_p File.dirname target

    content = File.open(source, 'r') { |f| f.read.gsub(/enabled/, 'disabled') }
    File.open(target, 'w') { |f| f.write content }
    rake_output_message "Disabled remote downloads in #{target}" if verbose
  end
end