Class: Pod::Command::UseLatestTag

Inherits:
Pod::Command show all
Defined in:
lib/pod/command/use_latest_tag.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ UseLatestTag

Returns a new instance of UseLatestTag.



24
25
26
27
# File 'lib/pod/command/use_latest_tag.rb', line 24

def initialize(argv)
  @check_command_verbose = argv.flag?('verbose')
  super
end

Class Method Details

.optionsObject



18
19
20
21
22
# File 'lib/pod/command/use_latest_tag.rb', line 18

def self.options
  [
      ['--verbose', 'Show change details.']
  ].concat(super)
end

Instance Method Details

#change_podfile(config) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/pod/command/use_latest_tag.rb', line 38

def change_podfile(config)
  target_pods = {}
  config.podfile.dependencies.each do |dependency|
    if dependency.external? && (dependency.external_source[:branch] != nil || dependency.external_source[:tag] != nil)
      target_pods[dependency.name] = dependency.external_source.clone
    end
  end
  target_pod_names = target_pods.keys

  target_pod_names.sort.uniq.map do |spec_name|
    git_path = target_pods[spec_name][:git].gsub("/", '\/')
    # get latest tag for spec
    latest_tag = get_latest_tag(target_pods[spec_name])
    next if latest_tag.empty?

    exp = ""
    preview_version = ""
    latest_version = "latest_tag: #{latest_tag}"
    if target_pods[spec_name][:tag] != nil && target_pods[spec_name][:tag] != latest_tag
      # preview use tag
      exp = "/#{git_path}/s/:tag[ ]*=>[ ]*'[^']*'/:tag => '#{latest_tag}'/"
      preview_version = "preview_tag: #{target_pods[spec_name][:tag]}"
    elsif target_pods[spec_name][:branch] != nil
      # preview use branch
      exp = %(/#{git_path}/s/:branch[ ]*=>[ ]*'[^']*'/:tag => '#{latest_tag}'/)
      preview_version = "preview_branch: #{target_pods[spec_name][:branch]}"
    end
    next if exp.empty?

    # sed command
    command = %(sed -i '' -E "#{exp}" Podfile)
    if @check_command_verbose
      UI.puts "Command: #{command}"
    end
    `#{command}`

    # cache changed result
    changed_result(spec_name, preview_version, latest_version)
  end.compact
end

#changed_result(spec_name, preview_version, latest_version) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/pod/command/use_latest_tag.rb', line 88

def changed_result(spec_name, preview_version, latest_version)
  if @check_command_verbose
    "#{spec_name} #{preview_version} -> #{latest_version}"
  else
    "~#{spec_name}"
  end
end

#get_latest_tag(external_source) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/pod/command/use_latest_tag.rb', line 79

def get_latest_tag(external_source)
  command = "git ls-remote --tags --refs --sort='v:refname' #{external_source[:git]} | tail -n1 | sed 's/.*\\///'"
  latest_tag = (`#{command}` || '').strip
  if @check_command_verbose
    UI.puts "Fetch latest tag for #{external_source[:git]} -> #{latest_tag}"
  end
  return latest_tag
end

Raises:

  • (Informative)


96
97
98
99
100
101
102
103
104
105
106
# File 'lib/pod/command/use_latest_tag.rb', line 96

def print_results(results)
  return UI.puts "The Podfile's dependencies all use latest tag." if results.empty?

  if @check_command_verbose
    UI.puts results.join("\n")
  else
    UI.puts results.join(', ')
  end

  raise Informative, "#{results.length} Pod#{'s' if results.length > 1} has been changed to use the latest tag. Please double check the Podfile's changes."
end

#runObject



29
30
31
32
33
34
35
36
# File 'lib/pod/command/use_latest_tag.rb', line 29

def run
  unless config.podfile
    raise Informative, 'Missing Podfile!'
  end

  results = change_podfile(config)
  print_results(results)
end