Module: Flutter::Pub::Downloader

Defined in:
lib/cocoapods-embed-flutter/flutter/downloader.rb

Overview

The Downloader modules name-spaces all the classes and methods for downloading and caching remote Flutter projects.

Class Method Summary collapse

Class Method Details

.download(request, target, can_cache: true, cache_path: Pod::Config.instance.cache_root + 'Pods') ⇒ Response

TODO:

Implement caching for remote sources.

Downloads a package from the given ‘request` to the given `target` location.

Parameters:

  • request (Request)

    the request that describes the flutter project download.

  • target (Pathname, Nil)

    the location to which the flutter project should be downloaded.

  • can_cache (Boolean) (defaults to: true)

    whether caching is allowed.

  • cache_path (Pathname, Nil) (defaults to: Pod::Config.instance.cache_root + 'Pods')

    the path used to cache flutter project downloads.

Returns:

  • (Response)

    The download response for this download.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cocoapods-embed-flutter/flutter/downloader.rb', line 28

def self.download(
  request,
  target,
  can_cache: true,
  cache_path: Pod::Config.instance.cache_root + 'Pods'
)
  can_cache &&= !Pod::Config.instance.skip_download_cache

  request = Pod::Downloader.preprocess_request(request)

  # if can_cache
  #   raise ArgumentError, 'Must provide a `cache_path` when caching.' unless cache_path
  #   cache = Pod::Downloader::Cache.new(cache_path)
  #   result = cache.download_pod(request)
  # else
  #   raise ArgumentError, 'Must provide a `target` when caching is disabled.' unless target

  #   result, = Pod::Downloader.download_request(request, target)
  #   Pod::Installer::PodSourcePreparer.new(result.spec, result.location).prepare!
  # end
  raise ArgumentError, 'Must provide a `target` when caching is disabled.' unless target
  result, = Pod::Downloader.download_request(request, target)

  if target && result.location && target != result.location
    Pod::UI.message "Copying #{request.name} from `#{result.location}` to #{UI.path target}", '> ' do
      Pod::Downloader::Cache.read_lock(result.location) do
        FileUtils.rm_rf target
        FileUtils.cp_r(result.location, target)
      end
    end
  end
  result
end