Class: Pod::Downloader::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/downloader/request.rb

Overview

This class represents a download request for a given Pod.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec: nil, released: false, name: nil, params: false) ⇒ Request

Initialize a new instance

Parameters:

  • spec (Specification, Nil) (defaults to: nil)

    see #spec

  • released (Boolean) (defaults to: false)
  • name (String, Nil) (defaults to: nil)

    see #name

  • params (Hash<Symbol,String>, Nil) (defaults to: false)

    see #params



40
41
42
43
44
45
46
47
# File 'lib/cocoapods/downloader/request.rb', line 40

def initialize(spec: nil, released: false, name: nil, params: false)
  @released_pod = released
  @spec = spec
  @params = spec ? (spec.source && spec.source.dup) : params
  @name = spec ? spec.name : name

  validate!
end

Instance Attribute Details

#nameString (readonly)

Returns The name of the pod whose dowload is being requested.

Returns:

  • (String)

    The name of the pod whose dowload is being requested.



20
21
22
# File 'lib/cocoapods/downloader/request.rb', line 20

def name
  @name
end

#paramsHash<Symbol, String> (readonly)

Returns The download parameters for this request.

Returns:

  • (Hash<Symbol, String>)

    The download parameters for this request.



24
25
26
# File 'lib/cocoapods/downloader/request.rb', line 24

def params
  @params
end

#released_podBoolean (readonly) Also known as: released_pod?

Returns Whether this download request is for a released pod.

Returns:

  • (Boolean)

    Whether this download request is for a released pod.



15
16
17
# File 'lib/cocoapods/downloader/request.rb', line 15

def released_pod
  @released_pod
end

#specSpecification, Nil (readonly)

Returns The specification for the pod whose download is being requested.

Returns:

  • (Specification, Nil)

    The specification for the pod whose download is being requested.



11
12
13
# File 'lib/cocoapods/downloader/request.rb', line 11

def spec
  @spec
end

Instance Method Details

#slug(name: self.name, params: self.params, spec: self.spec) ⇒ String

Returns The slug used to store the files resulting from this download request.

Parameters:

  • name (String) (defaults to: self.name)

    the name of the pod being downloaded.

  • params (Hash<#to_s, #to_s>) (defaults to: self.params)

    the download parameters of the pod being downloaded.

  • spec (Specification) (defaults to: self.spec)

    the specification of the pod being downloaded.

Returns:

  • (String)

    The slug used to store the files resulting from this download request.



61
62
63
64
65
66
67
68
69
70
# File 'lib/cocoapods/downloader/request.rb', line 61

def slug(name: self.name, params: self.params, spec: self.spec)
  checksum = spec && spec.checksum && '-' << spec.checksum[0, 5]
  if released_pod?
    "Release/#{name}/#{spec.version}#{checksum}"
  else
    opts = params.to_a.sort_by(&:first).map { |k, v| "#{k}=#{v}" }.join('-')
    digest = Digest::MD5.hexdigest(opts)
    "External/#{name}/#{digest}#{checksum}"
  end
end

#validate!Void (private)

Validates that the given request is well-formed.

Returns:

  • (Void)

Raises:

  • (ArgumentError)


78
79
80
81
82
83
# File 'lib/cocoapods/downloader/request.rb', line 78

def validate!
  raise ArgumentError, 'Requires a name' unless name
  raise ArgumentError, 'Must give a spec for a released download request' if released_pod? && !spec
  raise ArgumentError, 'Requires a version if released' if released_pod? && !spec.version
  raise ArgumentError, 'Requires params' unless params
end