Method: Pod::Lockfile#detect_changes_with_podfile

Defined in:
lib/cocoapods-core/lockfile.rb

#detect_changes_with_podfile(podfile) ⇒ Hash{Symbol=>Array[Strings]}

TODO:

Why do we look for compatibility instead of just comparing if the two dependencies are equal?

Analyzes the Pod::Lockfile and detects any changes applied to the Podfile since the last installation.

For each Pod, it detects one state among the following:

  • added: Pods that weren’t present in the Podfile.

  • changed: Pods that were present in the Podfile but changed:

    • Pods whose version is not compatible anymore with Podfile,

    • Pods that changed their external options.

  • removed: Pods that were removed form the Podfile.

  • unchanged: Pods that are still compatible with Podfile.

Parameters:

  • podfile (Podfile)

    the podfile that should be analyzed.

Returns:

  • (Hash{Symbol=>Array[Strings]})

    a hash where pods are grouped by the state in which they are.



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/cocoapods-core/lockfile.rb', line 289

def detect_changes_with_podfile(podfile)
  result = {}
  [:added, :changed, :removed, :unchanged].each { |k| result[k] = [] }

  installed_deps = {}
  dependencies.each do |dep|
    name = dep.root_name
    installed_deps[name] ||= dependencies_to_lock_pod_named(name)
  end

  installed_deps = installed_deps.values.flatten(1).group_by(&:name)

  podfile_dependencies = podfile.dependencies
  podfile_dependencies_by_name = podfile_dependencies.group_by(&:name)

  all_dep_names = (dependencies + podfile_dependencies).map(&:name).uniq
  all_dep_names.each do |name|
    installed_dep   = installed_deps[name]
    installed_dep &&= installed_dep.first
    podfile_dep     = podfile_dependencies_by_name[name]
    podfile_dep   &&= podfile_dep.first

    if installed_dep.nil?  then key = :added
    elsif podfile_dep.nil? then key = :removed
    elsif podfile_dep.compatible?(installed_dep) then key = :unchanged
    else key = :changed
    end
    result[key] << name
  end
  result
end