Sha256: 8d5b664358f15e8c257b9f50a112177e37bd037bc3aa3bad7f03f891dd6a2389

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'cocoapods'

module CocoaPodsKeys
  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

    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
      ui = Pod::UserInterface
      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
          ui.print ' > '
          answer = ui.gets.strip
          break if answer.length > 0
        end
        answer
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cocoapods-keys-1.3.2 lib/name_whisperer.rb