class Rake::Funnel::Tasks::BinPath

Attributes

name[RW]
path_modifier[RW]
search_pattern[RW]

Public Class Methods

new(*args, &task_block) click to toggle source
# File lib/rake/funnel/tasks/bin_path.rb, line 11
def initialize(*args, &task_block)
  setup_ivars(args)

  define(args, &task_block)
end

Private Instance Methods

define(args) { |*[self, task_args].slice(0, arity)| ... } click to toggle source
# File lib/rake/funnel/tasks/bin_path.rb, line 25
def define(args, &task_block) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  desc 'Add local binaries to PATH environment variable' unless Rake.application.last_description

  task(name, *args) do |_, task_args|
    yield(*[self, task_args].slice(0, task_block.arity)) if task_block

    next unless paths.any?

    prepend_pattern_to_path_environment(paths)
    $stderr.print "Added the following paths to the PATH environment variable:\n"
    paths.each do |p|
      $stderr.print "  - #{p}\n"
    end
  end

  self
end
paths() click to toggle source
# File lib/rake/funnel/tasks/bin_path.rb, line 43
def paths
  @paths ||= @path_modifier.call(Dir[*search_pattern].select { |path| File.directory?(path) })
                           .map { |path| File.expand_path(path) }
                           .sort
end
prepend_pattern_to_path_environment(paths) click to toggle source
# File lib/rake/funnel/tasks/bin_path.rb, line 49
def prepend_pattern_to_path_environment(paths)
  ENV['PATH'] = ([] << paths << ENV['PATH']).flatten.join(File::PATH_SEPARATOR)
  paths
end
setup_ivars(args) click to toggle source
# File lib/rake/funnel/tasks/bin_path.rb, line 19
def setup_ivars(args)
  @name = args.shift || :bin_path
  @search_pattern = %w(tools/* tools/*/bin packages/**/tools)
  @path_modifier = proc { |paths| paths }
end