Skip to content

Commit

Permalink
update podfile automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Jul 5, 2017
1 parent 40aa79c commit 6f4729e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lib/anticuado/ios/cocoapods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ def self.format(outdated)
end
}.compact
end

# @param [String] pod_file_in The file path to Podfile you'd like to update
# @param [String] pod_file_out The file path to new Podfile updated. Default is nil and then `pod_file_in` is used
# as the file path
# @param [Hash] library_name The library name you'd like to update
# [{library_name: "version"}]
# @return [Array] Array include outdated data.
# If target project have no outdated data, then return blank array such as `[]`
def self.update(pod_file_in:, pod_file_out: nil, library_name:, new:)
pod_file_out = pod_file_in if pod_file_out.nil?
current_pod = File.read(pod_file_in)

result = current_pod.each_line.reduce("") do |memo, line|
memo << ((line.strip.start_with?("pod ") && line.include?(library_name)) ? line.sub(/[0-9|.]+/, new) : line)
end

File.write(pod_file_out, result)
end
end # class CocoaPods
end # module IOS
end # module Anticuado
9 changes: 9 additions & 0 deletions test/anticuado/ios/cocoapod_actual
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pod 'AFNetworking', '~> 3.0'

target 'Example' do
pod 'OHHTTPStubs', '~> 4.1.0'
end

target 'Example2' do
pod 'EarlGrey'
end
9 changes: 9 additions & 0 deletions test/anticuado/ios/cocoapod_expected1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pod 'AFNetworking', '~> 4.0'

target 'Example' do
pod 'OHHTTPStubs', '~> 4.1.0'
end

target 'Example2' do
pod 'EarlGrey'
end
9 changes: 9 additions & 0 deletions test/anticuado/ios/cocoapod_expected2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pod 'AFNetworking', '~> 3.0'

target 'Example' do
pod 'OHHTTPStubs', '~> 4.2.0'
end

target 'Example2' do
pod 'EarlGrey'
end
31 changes: 30 additions & 1 deletion test/anticuado/ios/cocoapods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ def test_with_format_no_update
assert_equal expected, result
end

def test_with_update_cocoapod
expected = File.read("test/anticuado/ios/cocoapod_expected1")

actual_file_path = "test/anticuado/ios/cocoapod_actual"
actual_output_file_path = "test/anticuado/ios/cocoapod_actual_out"

Anticuado::IOS::CocoaPods.update(pod_file_in: actual_file_path, pod_file_out: actual_output_file_path, library_name: "AFNetworking", new: "4.0")

actual = File.read(actual_output_file_path)

assert_equal expected, actual

File.delete(actual_output_file_path)
end

def test_with_update_cocoapod1
expected = File.read("test/anticuado/ios/cocoapod_expected2")

actual_file_path = "test/anticuado/ios/cocoapod_actual"
actual_output_file_path = "test/anticuado/ios/cocoapod_actual_out"

Anticuado::IOS::CocoaPods.update(pod_file_in: actual_file_path, pod_file_out: actual_output_file_path, library_name: "OHHTTPStubs", new: "4.2.0")

actual = File.read(actual_output_file_path)

assert_equal expected, actual

File.delete(actual_output_file_path)
end
end
end
end
end

0 comments on commit 6f4729e

Please sign in to comment.