Is the heuristic CocoaPods uses for the “pod try” command documented anywhere?

微笑、不失礼 提交于 2019-12-04 03:20:36

I was looking for this as well and the only thing I got was the source of the pod-try plugin:

# Picks a project or workspace suitable for the demo purposes in the
# given directory.
#
# To decide the project simple heuristics are used according to the name,
# if no project is found this method raises and `Informative` otherwise
# if more than one project is found the choice is presented to the user.
#
# @param  [#to_s] dir
#         The path where to look for projects.
#
# @return [String] The path of the project.
#
def pick_demo_project(dir)
  projs = projects_in_dir(dir)
  if projs.count == 0
    raise Informative, 'Unable to find any project in the source files' \
      " of the Pod: `#{dir}`"
  elsif projs.count == 1
    projs.first
  elsif (workspaces = projs.grep(/(demo|example).*\.xcworkspace$/i)).count == 1
    workspaces.first
  elsif (projects = projs.grep(/demo|example/i)).count == 1
    projects.first
  else
    message = 'Which project would you like to open'
    selection_array = projs.map do |p|
      Pathname.new(p).relative_path_from(dir).to_s
    end
    index = choose_from_array(selection_array, message)
    projs[index]
  end
end

I don't know Ruby, but seems that it gets the list of all XCode projects/workspaces (except the Pods project and the projects that have a sister workspace) and picks:

  1. The only item if there's only one item found.
  2. The only workspace that has "demo" or "example" in filename if there's only one such item found.
  3. The only project that has "demo" or "example" in filename if there's only one such item found.
  4. Nothing, but let's you choose from all the items found.

If somebody has corrections to this - they're welcomed, as I'm no Ruby guy.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!