lib/name_whisperer.rb in cocoapods-keys-1.2.1 vs lib/name_whisperer.rb in cocoapods-keys-1.3.0
- old
+ new
@@ -1,44 +1,40 @@
require 'cocoapods'
module CocoaPodsKeys
- class NameWhisperer
-
- def self.get_project_name()
- podfile = Pod::Podfile.from_file("Podfile") rescue nil
- if podfile
- user_xcodeproj = xcodeproj_from_podfile(podfile)
- end
- user_xcodeproj ||= self.search_folders_for_xcodeproj
- user_xcodeproj.gsub(".xcodeproj", "")
+ class NameWhisperer
+ def self.get_project_name
+ podfile = Pod::Config.instance.podfile
+ if podfile
+ user_xcodeproj = xcodeproj_from_podfile(podfile)
end
+ user_xcodeproj ||= search_folders_for_xcodeproj
+ user_xcodeproj.basename('.xcodeproj')
+ end
- :private
+ private
- def self.xcodeproj_from_podfile(podfile)
- if podfile.target_definition_list.length > 0
- return podfile.target_definition_list[0].user_project_path
- end
- nil
+ def self.xcodeproj_from_podfile(podfile)
+ unless podfile.target_definition_list.empty?
+ return podfile.target_definition_list.first.user_project_path
end
+ end
- def self.search_folders_for_xcodeproj
- xcodeprojects = Dir.glob("**/**/*.xcodeproj")
- if xcodeprojects.length == 1
- Pathname.new(xcodeprojects[0]).basename.to_s
- else
- error_message = (xcodeprojects.length > 1) ? "found too many" : "couldn't find any"
- puts "CocoaPods-Keys " + error_message + " Xcode projects. Please give a name for this project."
+ def self.search_folders_for_xcodeproj
+ xcodeprojects = Pathname.glob('**/*.xcodeproj')
+ if xcodeprojects.length == 1
+ Pathname(xcodeprojects.first).basename
+ else
+ error_message = (xcodeprojects.length > 1) ? 'found too many' : "couldn't find any"
+ UI.puts 'CocoaPods-Keys ' + error_message + ' Xcode projects. Please give a name for this project.'
- answer = ""
- loop do
- print " > "
- answer = STDIN.gets.chomp
- break if answer.length > 0
- end
- answer
-
+ answer = ''
+ loop do
+ UI.print ' > '
+ answer = UI.gets.strip
+ break if answer.length > 0
end
+ answer
end
-
end
+ end
end