Module: WatchTower::Project::GitBased
- Extended by:
- GitBased
- Includes:
- AnyBased
- Included in:
- GitBased
- Defined in:
- lib/watch_tower/project/git_based.rb
Constant Summary collapse
- @@working_cache =
Cache for working_directory by path The key is the path to a file, the value is the working directory of this path
Hash.new
- @@project_name_cache =
Cache for project_name by path The key is the path to a file, the value is the project’s name
Hash.new
- @@project_git_folder_path =
Cache for project git path The key is the path to a file, the value is the project’s parts
Hash.new
Instance Method Summary collapse
-
#active_for_path?(path, options = {}) ⇒ Boolean
Check if the path is under Git.
- #head(path) ⇒ Object
- #log(path) ⇒ Object
-
#project_name(path, options = {}) ⇒ String
Return the project’s name from a path to any file inside the project.
-
#working_directory(path, options = {}) ⇒ String
Return the working directory (the project’s path if you will) from a path to any file inside the project.
Methods included from AnyBased
Instance Method Details
#active_for_path?(path, options = {}) ⇒ Boolean
Check if the path is under Git
29 30 31 32 |
# File 'lib/watch_tower/project/git_based.rb', line 29 def active_for_path?(path, = {}) path = path project_git_folder_path(path).present? end |
#head(path) ⇒ Object
61 62 63 |
# File 'lib/watch_tower/project/git_based.rb', line 61 def head(path) log(path).first end |
#log(path) ⇒ Object
65 66 67 68 |
# File 'lib/watch_tower/project/git_based.rb', line 65 def log(path) g = Grit::Repo.new(path) g.commits end |
#project_name(path, options = {}) ⇒ String
Return the project’s name from a path to any file inside the project
53 54 55 56 57 58 59 |
# File 'lib/watch_tower/project/git_based.rb', line 53 def project_name(path, = {}) path = path return @@project_name_cache[path] if @@project_name_cache.key?(path) @@project_name_cache[path] = File.basename working_directory(path, ) @@project_name_cache[path] end |
#working_directory(path, options = {}) ⇒ String
Return the working directory (the project’s path if you will) from a path to any file inside the project
40 41 42 43 44 45 46 |
# File 'lib/watch_tower/project/git_based.rb', line 40 def working_directory(path, = {}) path = path return @@working_cache[path] if @@working_cache.key?(path) @@working_cache[path] = File.dirname(project_git_folder_path(path)) @@working_cache[path] end |