Sha256: 71edf6ad6b6b144642a89642f05b4da0776ba711582f67897eee8a4bb16a9c79

Contents?: true

Size: 1.17 KB

Versions: 9

Compression:

Stored size: 1.17 KB

Contents

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", "")
      end

    :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
      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 "Hello there, we " + error_message + " xcodeprojects. Please give a name for this project."

          answer = ""
          loop do
            print " > "
            answer = STDIN.gets.chomp
            break if answer.length > 0
          end
          answer

        end
      end

    end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cocoapods-keys-1.0.2 lib/name_whisperer.rb
cocoapods-keys-1.0.1 lib/name_whisperer.rb
cocoapods-keys-1.0.0 lib/name_whisperer.rb
cocoapods-keys-0.9.5 lib/name_whisperer.rb
cocoapods-keys-0.9.0 lib/name_whisperer.rb
cocoapods-keys-0.6.2 lib/name_whisperer.rb
cocoapods-keys-0.6.1 lib/name_whisperer.rb
cocoapods-keys-0.6.0 lib/name_whisperer.rb
cocoapods-keys-0.5.2 lib/name_whisperer.rb