Module: ZergXcode::Paths

Defined in:
lib/zerg_xcode/file_format/paths.rb

Class Method Summary collapse

Class Method Details

.project_file_at(base_path) ⇒ Object

The most likely project file name for the given path.


3
4
5
6
7
8
9
10
11
12
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
# File 'lib/zerg_xcode/file_format/paths.rb', line 3

def self.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.


40
41
42
43
# File 'lib/zerg_xcode/file_format/paths.rb', line 40

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