Class: DownloadCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/download_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ DownloadCommand

Returns a new instance of DownloadCommand.



17
18
19
20
21
# File 'lib/commands/download_command.rb', line 17

def initialize(args)
  @config = args[:config]
  @networking = args[:networking]
  @api = args[:api]
end

Class Method Details

.new_with_defaults(options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/commands/download_command.rb', line 4

def self.new_with_defaults(options)
  shell = ShellWrapper.new
  config = Configuration.new(shell)
  networking = Networking.new(config)
  api = API.new(shell, networking, options)

  DownloadCommand.new(
    config: config,
    networking: networking,
    api: api,
  )
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/commands/download_command.rb', line 23

def run
  pool = Concurrent::FixedThreadPool.new(THREAD_POOL_SIZE)

  @number_of_downloaded_archives = 0
  @number_of_skipped_archives = 0
  @total_archive_size = 0
  errors = Concurrent::Array.new

  for carthage_dependency in @config.carthage_dependencies
    pool.post(carthage_dependency) do |carthage_dependency|
      begin
        download(carthage_dependency)
      rescue => e
        errors << e
      end
    end
  end

  pool.shutdown
  pool.wait_for_termination

  if errors.count > 0
    raise MultipleErrorsError.new(errors)
  else
    puts "Downloaded and extracted #{@number_of_downloaded_archives} archives " +
           "(#{format_file_size(@total_archive_size)}), " +
           "skipped #{@number_of_skipped_archives} archives."
  end
end