Module: ProjectFinder
- Defined in:
- lib/lokale/find_dir.rb
Class Method Summary collapse
-
.find_git_repo(start_path = '.') ⇒ Object
Returns the git root directory given a path inside the repo.
- .find_proj ⇒ Object
-
.root_directory?(file_path) ⇒ Boolean
Returns true if the given path represents a root directory (/ or C:/).
- .xcode_project_name(path) ⇒ Object
Class Method Details
.find_git_repo(start_path = '.') ⇒ Object
Returns the git root directory given a path inside the repo. Returns nil if the path is not in a git repo.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lokale/find_dir.rb', line 17 def self.find_git_repo(start_path = '.') raise NoSuchPathError unless File.exists?(start_path) current_path = File.(start_path) # for clarity: set to an explicit nil and then just return whatever # the current value of this variable is (nil or otherwise) return_path = nil until root_directory?(current_path) if File.exists?(File.join(current_path, '.git')) # done return_path = current_path break else # go up a directory and try again current_path = File.dirname(current_path) end end return_path end |
.find_proj ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lokale/find_dir.rb', line 47 def self.find_proj project_path = find_git_repo if project_path.nil? raise "Could not find any git repository." end project_name = xcode_project_name(project_path) if project_name.nil? raise "Found git repository (#{project_path}) does not contain an Xcode project." end return project_path, project_name end |
.root_directory?(file_path) ⇒ Boolean
Returns true if the given path represents a root directory (/ or C:/)
8 9 10 11 12 13 |
# File 'lib/lokale/find_dir.rb', line 8 def self.root_directory?(file_path) # Implementation inspired by http://stackoverflow.com/a/4969416: # Does file + ".." resolve to the same directory as file_path? File.directory?(file_path) && File.(file_path) == File.(File.join(file_path, '..')) end |
.xcode_project_name(path) ⇒ Object
41 42 43 |
# File 'lib/lokale/find_dir.rb', line 41 def self.xcode_project_name(path) Dir.glob("#{path}/**/**") { |file| return $1 if file =~ /\/(.+?)\.(?:xcodeproj|xcworkspace)$/ } end |