Class: Pod::Command::Update

Inherits:
Pod::Command show all
Includes:
ProjectDirectory, RepoUpdate
Defined in:
lib/cocoapods/command/update.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pod::Command

#ensure_master_spec_repo_exists!, ensure_not_root_or_allowed!, git_version, #installer_for_config, report_error, run, #verify_lockfile_exists!, verify_minimum_git_version!, #verify_podfile_exists!, verify_xcode_license_approved!

Methods included from Pod::Config::Mixin

#config

Constructor Details

#initialize(argv) ⇒ Update

Returns a new instance of Update.


32
33
34
35
36
37
38
39
40
41
# File 'lib/cocoapods/command/update.rb', line 32

def initialize(argv)
  @pods = argv.arguments!

  @source_urls = argv.option('sources', '').split(',')
  @excluded_pods = argv.option('exclude-pods', '').split(',')
  @clean_install = argv.flag?('clean-install', false)
  @source_pods = @source_urls.flat_map { |url| config.sources_manager.source_with_name_or_url(url).pods }

  super
end

Class Method Details

.optionsObject


22
23
24
25
26
27
28
29
30
# File 'lib/cocoapods/command/update.rb', line 22

def self.options
  [
    ["--sources=#{Pod::TrunkSource::TRUNK_REPO_URL}", 'The sources from which to update dependent pods. ' \
     'Multiple sources must be comma-delimited'],
    ['--exclude-pods=podName', 'Pods to exclude during update. Multiple pods must be comma-delimited'],
    ['--clean-install', 'Ignore the contents of the project cache and force a full pod installation. This only ' \
     'applies to projects that have enabled incremental installation'],
  ].concat(super)
end

Instance Method Details

#lockfile_missing_pods(pods) ⇒ Object (private)


98
99
100
101
# File 'lib/cocoapods/command/update.rb', line 98

def lockfile_missing_pods(pods)
  lockfile_roots = config.lockfile.pod_names.map { |pod| Specification.root_name(pod) }
  pods.map { |pod| Specification.root_name(pod) }.uniq - lockfile_roots
end

#runObject


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cocoapods/command/update.rb', line 43

def run
  verify_podfile_exists!

  installer = installer_for_config
  installer.repo_update = repo_update?(:default => true)
  installer.clean_install = @clean_install
  if @pods.any? || @excluded_pods.any? || @source_pods.any?
    verify_lockfile_exists!
    verify_pods_are_installed!
    verify_excluded_pods_are_installed!

    @pods += @source_pods.select { |pod| config.lockfile.pod_names.include?(pod) }
    @pods = config.lockfile.pod_names.dup if @pods.empty?
    @pods -= @excluded_pods

    installer.update = { :pods => @pods }
  else
    UI.puts 'Update all pods'.yellow
    installer.update = true
  end
  installer.install!
end

#verify_excluded_pods_are_installed!Object (private)

Check if excluded pods are installed


87
88
89
90
91
92
93
94
95
96
# File 'lib/cocoapods/command/update.rb', line 87

def verify_excluded_pods_are_installed!
  missing_pods = lockfile_missing_pods(@excluded_pods)

  unless missing_pods.empty?
    pluralized_words = missing_pods.length > 1 ? %w(Pods are) : %w(Pod is)
    message = "Trying to skip `#{missing_pods.join('`, `')}` #{pluralized_words.first} " \
            "which #{pluralized_words.last} not installed"
    raise Informative, message
  end
end

#verify_pods_are_installed!Object (private)

Check if all given pods are installed


70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cocoapods/command/update.rb', line 70

def verify_pods_are_installed!
  missing_pods = lockfile_missing_pods(@pods)

  unless missing_pods.empty?
    message = if missing_pods.length > 1
                "Pods `#{missing_pods.join('`, `')}` are not " \
                    'installed and cannot be updated'
              else
                "The `#{missing_pods.first}` Pod is not installed " \
                    'and cannot be updated'
              end
    raise Informative, message
  end
end