Top Level Namespace
Defined Under Namespace
Modules: Lokale Classes: Action, Settings, String
Instance Method Summary collapse
-
#find_git_repo(start_path = '.') ⇒ Object
Returns the git root directory given a path inside the repo.
-
#root_directory?(file_path) ⇒ Boolean
Returns true if the given path represents a root directory (/ or C:/).
- #xcode_project_name(path) ⇒ Object
Instance 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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lokale/find_dir.rb', line 15 def 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 |
#root_directory?(file_path) ⇒ Boolean
Returns true if the given path represents a root directory (/ or C:/)
6 7 8 9 10 11 |
# File 'lib/lokale/find_dir.rb', line 6 def 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
37 38 39 |
# File 'lib/lokale/find_dir.rb', line 37 def xcode_project_name(path) Dir.glob("#{path}/**/**") { |file| return $1 if file =~ /\/(.+?)\.(?:xcodeproj|xcworkspace)$/ } end |