Sha256: 06a13467d2c1cd72af3cce6b7d9d8f31155ac4b8a42a872524c3286ab24ae5b9

Contents?: true

Size: 1.23 KB

Versions: 15

Compression:

Stored size: 1.23 KB

Contents

require 'rake/tasklib'

module Rake
  module Funnel
    module Tasks
      class BinPath < Rake::TaskLib
        attr_accessor :name, :search_pattern

        def initialize(*args, &task_block)
          setup_ivars(args)

          define(args, &task_block)
        end

        private
        def setup_ivars(args)
          @name = args.shift || :bin_path
          @search_pattern = %w(tools/* tools/*/bin packages/**/tools)
        end

        def define(args, &task_block)
          desc 'Add local binaries to PATH environment variable' unless Rake.application.last_description

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

            Rake.rake_output_message 'Added the following paths to the PATH environment variable:'
            add_pattern_to_path_environment.each do |p|
              Rake.rake_output_message "  - #{p}"
            end
          end

          self
        end

        def add_pattern_to_path_environment
          paths = Dir[*search_pattern].map { |path| File.expand_path(path) }.sort

          ENV['PATH'] = ([] << paths << ENV['PATH']).flatten.join(File::PATH_SEPARATOR)
          paths
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rake-funnel-0.16.0 lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.15.0.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.14.0.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.13.0.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.12.0.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.11.0.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.10.0.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.9.1.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.9.0.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.8.0.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.7.0.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.6.1.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.6.0.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.5.0.pre lib/rake/funnel/tasks/bin_path.rb
rake-funnel-0.4.0.pre lib/rake/funnel/tasks/bin_path.rb