Module: ZergXcode::Paths
- Defined in:
- lib/zerg_xcode/file_format/paths.rb
Overview
Finds the .pbxproj file inside an Xcode project.
Class Method Summary collapse
-
.project_file_at(base_path) ⇒ Object
The most likely project file name for the given path.
-
.project_root_at(base_path) ⇒ Object
The most likely project root dir for the given path.
Class Method Details
.project_file_at(base_path) ⇒ Object
The most likely project file name for the given path.
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 48 |
# File 'lib/zerg_xcode/file_format/paths.rb', line 14 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.
51 52 53 54 |
# File 'lib/zerg_xcode/file_format/paths.rb', line 51 def self.project_root_at(base_path) file = project_file_at base_path File.dirname File.dirname(file) end |