Class: Pod::ExternalSources::AbstractExternalSource

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/external_sources/abstract_external_source.rb

Overview

Abstract class that defines the common behaviour of external sources.

Direct Known Subclasses

DownloaderSource, PathSource, PodspecSource

Instance Attribute Summary collapse

Subclasses hooks collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, params, podfile_path, can_cache = true) ⇒ AbstractExternalSource

Initialize a new instance

Parameters:

  • name (String)

    @see #name

  • params (Hash)

    @see #params

  • podfile_path (String)

    @see #podfile_path

  • can_cache (Boolean) (defaults to: true)

    @see #can_cache



32
33
34
35
36
37
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 32

def initialize(name, params, podfile_path, can_cache = true)
  @name = name
  @params = params
  @podfile_path = podfile_path
  @can_cache = can_cache
end

Instance Attribute Details

#can_cacheBoolean (readonly) Also known as: can_cache?

Returns Whether the source is allowed to touch the cache.

Returns:

  • (Boolean)

    Whether the source is allowed to touch the cache.



22
23
24
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 22

def can_cache
  @can_cache
end

#nameString (readonly)

Returns the name of the Pod described by this external source.

Returns:

  • (String)

    the name of the Pod described by this external source.



8
9
10
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 8

def name
  @name
end

#paramsHash{Symbol => String} (readonly)

Returns the hash representation of the external source.

Returns:

  • (Hash{Symbol => String})

    the hash representation of the external source.



13
14
15
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 13

def params
  @params
end

#podfile_pathString (readonly)

Returns the path where the podfile is defined to resolve relative paths.

Returns:

  • (String)

    the path where the podfile is defined to resolve relative paths.



18
19
20
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 18

def podfile_path
  @podfile_path
end

Instance Method Details

#==(other) ⇒ Boolean

Returns whether an external source source is equal to another according to the #name and to the #params.

Returns:

  • (Boolean)

    whether an external source source is equal to another according to the #name and to the #params.



42
43
44
45
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 42

def ==(other)
  return false if other.nil?
  name == other.name && params == other.params
end

#descriptionString

Returns a string representation of the source suitable for UI.

Returns:

  • (String)

    a string representation of the source suitable for UI.



64
65
66
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 64

def description
  raise 'Abstract method'
end

#download_requestObject (private)



136
137
138
139
140
141
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 136

def download_request
  Downloader::Request.new(
    :name => name,
    :params => params,
  )
end

#fetch(_sandbox) ⇒ void

This method returns an undefined value.

Fetches the external source from the remote according to the params.

Parameters:

  • _sandbox (Sandbox)

    the sandbox where the specification should be stored.



58
59
60
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 58

def fetch(_sandbox)
  raise 'Abstract method'
end

#pre_download(sandbox) ⇒ void (private)

TODO:

The downloader configuration is the same of the

PodSourceInstaller and it needs to be kept in sync.

Note:

To prevent a double download of the repository the pod is marked as pre-downloaded indicating to the installer that only clean operations are needed.

This method returns an undefined value.

Pre-downloads a Pod passing the options to the downloader and informing the sandbox.

Parameters:

  • sandbox (Sandbox)

    The sandbox where the Pod should be downloaded.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 111

def pre_download(sandbox)
  title = "Pre-downloading: `#{name}` #{description}"
  UI.titled_section(title,  :verbose_prefix => '-> ') do
    target = sandbox.pod_dir(name)
    begin
      download_result = Downloader.download(download_request, target, :can_cache => can_cache)
    rescue Pod::DSLError => e
      raise Informative, "Failed to load '#{name}' podspec: #{e.message}"
    rescue => e
      raise Informative, "Failed to download '#{name}': #{e.message}"
    end

    spec = download_result.spec
    raise Informative, "Unable to find a specification for '#{name}'." unless spec

    # since the podspec might be cleaned, we want the checksum to refer
    # to the json in the sandbox
    spec.defined_in_file = nil

    store_podspec(sandbox, spec)
    sandbox.store_pre_downloaded_pod(name)
    sandbox.store_checkout_source(name, download_result.checkout_options)
  end
end

#store_podspec(sandbox, spec, json = false) ⇒ void (private)

Note:

All the concrete implementations of ##fetch should invoke this method.

Note:

The sandbox ensures that the podspec exists and that the names match.

This method returns an undefined value.

Stores the podspec in the sandbox and marks it as from an external source.

Parameters:

  • sandbox (Sandbox)

    The sandbox where the specification should be stored.

  • spec (Pathname, String, Specification)

    The path of the specification or its contents.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 160

def store_podspec(sandbox, spec, json = false)
  begin
    spec = case spec
           when Pathname
             Specification.from_file(spec)
           when String
             path = "#{name}.podspec"
             path << '.json' if json
             Specification.from_string(spec, path).tap { |s| s.defined_in_file = nil }
           when Specification
             spec.dup
           else
             raise "Unknown spec type: #{spec}"
           end
  rescue Pod::DSLError => e
    raise Informative, "Failed to load '#{name}' podspec: #{e.message}"
  end

  validate_podspec(spec)
  sandbox.store_podspec(name, spec, true, true)
end

#validate_podspec(podspec) ⇒ Object (private)



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 182

def validate_podspec(podspec)
  defined_in_file = podspec.defined_in_file
  podspec.defined_in_file = nil

  validator = validator_for_podspec(podspec)
  validator.quick = true
  validator.allow_warnings = true
  validator.ignore_public_only_results = true
  Config.instance.with_changes(:silent => true) do
    validator.validate
  end
  unless validator.validated?
    raise Informative, "The `#{name}` pod failed to validate due to #{validator.failure_reason}:\n#{validator.results_message}"
  end
ensure
  podspec.defined_in_file = defined_in_file
end

#validator_for_podspec(podspec) ⇒ Object (private)



200
201
202
# File 'lib/cocoapods/external_sources/abstract_external_source.rb', line 200

def validator_for_podspec(podspec)
  Validator.new(podspec, [], [])
end