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

Methods included from AnyBased

included

Instance Method Details

#active_for_path?(path, options = {}) ⇒ Boolean

Check if the path is under Git

Parameters:

  • path

    The path we should check if it’s under Git control

  • options (Hash) (defaults to: {})

    A hash of options

Returns:

  • (Boolean)

    boolean



29
30
31
32
# File 'lib/watch_tower/project/git_based.rb', line 29

def active_for_path?(path, options = {})
  path = expand_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

Parameters:

  • path

    The path to look the project path from

  • options (Hash) (defaults to: {})

    A hash of options

Returns:

  • (String)

    the project’s name



53
54
55
56
57
58
59
# File 'lib/watch_tower/project/git_based.rb', line 53

def project_name(path, options = {})
  path = expand_path path
  return @@project_name_cache[path] if @@project_name_cache.key?(path)

  @@project_name_cache[path] = File.basename working_directory(path, options)
  @@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

Parameters:

  • path

    The path to look the project path from

  • options (Hash) (defaults to: {})

    A hash of options

Returns:

  • (String)

    the project’s folder



40
41
42
43
44
45
46
# File 'lib/watch_tower/project/git_based.rb', line 40

def working_directory(path, options = {})
  path = expand_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