class Bundler::Download

Public Instance Methods

exec(command, args) click to toggle source
# File lib/bundler/download.rb, line 26
def exec(command, args)
  begin
    subcommand = extract_subcommand(args) || 'start'
    return puts("Invalid subcommand: #{subcommand} \nValid `bundle download` subcommands are: #{Bundler::Downloadfile::SUBCOMMANDS.join(' / ')}") unless Bundler::Downloadfile::SUBCOMMANDS.include?(subcommand)
    downloadfiles = Dir.glob(File.join(Gem.dir, 'gems', '**', 'Downloadfile')).to_a
    loaded_gems = Gem.loaded_specs.keys
    downloadfiles = downloadfiles.select {|df| loaded_gems.detect {|gem| File.basename(File.dirname(df)).include?(gem)} }
    downloadfiles << 'Downloadfile' if File.exist?('Downloadfile')
    puts 'No gems were found with Downloadfile.' if downloadfiles.empty?
    help_requested = subcommand == 'help' || subcommand == 'usage'
    help_shown = false
    downloadfiles.each do |downloadfile|
      bundler_downloadfile = Bundler::Downloadfile.new(
        downloadfile,
        gem_path: File.dirname(downloadfile),
        keep_existing: args.include?('--keep-existing'),
        all_operating_systems: args.include?('--all-operating-systems'),
      )
      if !help_requested || !help_shown
        puts "== bundler-download - Bundler Plugin - v#{File.read(File.expand_path('../../../VERSION', __FILE__)).strip} =="
        puts
        bundler_downloadfile.send(subcommand)
      end
      help_shown = true if help_requested
    end
    true
  rescue => e
    puts e.full_message
    false
  end
end

Private Instance Methods

extract_subcommand(args) click to toggle source
# File lib/bundler/download.rb, line 60
def extract_subcommand(args)
  args.detect {|arg| !arg.start_with?('-')}
end