Class: Pod::Command::ModifyDependencyVersion
- Inherits:
-
Pod::Command
- Object
- Pod::Command
- Pod::Command::ModifyDependencyVersion
- Defined in:
- lib/pod/command/modify_dependency_version.rb
Class Method Summary collapse
Instance Method Summary collapse
- #change_podfile(config) ⇒ Object
- #changed_result(spec_name, current_version, modify_version) ⇒ Object
-
#initialize(argv) ⇒ ModifyDependencyVersion
constructor
A new instance of ModifyDependencyVersion.
- #print_results(results) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ ModifyDependencyVersion
Returns a new instance of ModifyDependencyVersion.
25 26 27 28 29 30 31 |
# File 'lib/pod/command/modify_dependency_version.rb', line 25 def initialize(argv) @check_command_verbose = argv.flag?('verbose') @dependency_name = argv.option('name') @dependency_branch = argv.option('branch') @dependency_tag = argv.option('tag') super end |
Class Method Details
.options ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/pod/command/modify_dependency_version.rb', line 16 def self. [ ['--verbose', 'Show change details.'], ['--name', 'dependency name'], ['--branch', 'use branch name'], ['--tag', 'use tag'] ].concat(super) end |
Instance Method Details
#change_podfile(config) ⇒ Object
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 78 79 80 81 |
# File 'lib/pod/command/modify_dependency_version.rb', line 45 def change_podfile(config) target_pods = {} config.podfile.dependencies.each do |dependency| if dependency.name == @dependency_name && dependency.external? && (dependency.external_source[:branch] != nil || dependency.external_source[:tag] != nil) target_pods[dependency.name] = dependency.external_source.clone break end end target_pod_names = target_pods.keys return [] if target_pod_names.empty? target_pod_names.sort.uniq.map do |spec_name| git_path = target_pods[spec_name][:git].gsub("/", '\/') source_flag = target_pods[spec_name][:tag] != nil ? "tag" : "branch" target_flag = @dependency_tag != nil ? "tag" : "branch" source_value = target_pods[spec_name][:tag] != nil ? target_pods[spec_name][:tag] : target_pods[spec_name][:branch] target_value = @dependency_tag != nil ? @dependency_tag : @dependency_branch exp = "/#{git_path}/s/:#{source_flag}[ ]*=>[ ]*'[^']*'/:#{target_flag} => '#{target_value}'/" current_version = "current_#{source_flag}: #{source_value}" modify_version = "modify_#{target_flag}: #{target_value}" 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, current_version, modify_version) end.compact end |
#changed_result(spec_name, current_version, modify_version) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/pod/command/modify_dependency_version.rb', line 83 def changed_result(spec_name, current_version, modify_version) if @check_command_verbose "#{spec_name} #{current_version} -> #{modify_version}" else "~#{spec_name}" end end |
#print_results(results) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/pod/command/modify_dependency_version.rb', line 91 def print_results(results) return UI.puts "#{@dependency_name} not found." if results.empty? if @check_command_verbose UI.puts results.join("\n") else UI.puts results.join(', ') end end |
#run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pod/command/modify_dependency_version.rb', line 33 def run unless config.podfile raise Informative, 'Missing Podfile!' end raise Informative, 'Missing dependency name!' if @dependency_name == nil raise Informative, 'Missing branch name or tag!' if @dependency_branch == nil && @dependency_tag == nil results = change_podfile(config) print_results(results) end |