Module: ZergXcode::Paths

Included in:
ZergXcode
Defined in:
lib/zerg_xcode/paths.rb

Instance Method Summary collapse

Instance Method Details

#project_file_at(base_path) ⇒ Object

The most likely project file name for the given path.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/zerg_xcode/paths.rb', line 13

def project_file_at(base_path)
  return base_path if File.exist?(base_path) and File.file?(base_path)
  pbxfile = 'project.pbxproj'
  
  # naively assume the user gave the right name
  path = base_path
  path = path[0...-1] if path[-1, 1] == '/' || path[-1, 1] == '\\'
  path = path + '.xcodeproj' unless /\.xcodeproj$/ =~ path
  if File.exist? path
    file = File.join(path, pbxfile)
    return file
  end
  
  # didn't work, perhaps user gave us a path into their root
  entries = Dir.entries(base_path).sort_by do |entry|
    File.file?(File.join(base_path, entry)) ? 0 : 1
  end
  
  entries.each do |entry|
    next if entry == '..'
    path = File.join(base_path, entry)      
    case entry
    when /\.pbxproj$/
      return path
    when /\.xcodeproj$/
      return File.join(path, pbxfile)
    else
      if File.directory?(path) && File.exist?(File.join(path, pbxfile))
        return File.join(path, pbxfile)
      end
    end
  end
  
  raise "Could not find Xcode project at #{base_path}"
end

#project_root_at(base_path) ⇒ Object

The most likely project root dir for the given path.



50
51
52
53
# File 'lib/zerg_xcode/paths.rb', line 50

def project_root_at(base_path)
  file = project_file_at base_path
  File.dirname File.dirname(file)
end