Module: WatchTower::Project::PathBased

Extended by:
PathBased
Includes:
AnyBased
Included in:
PathBased
Defined in:
lib/watch_tower/project/path_based.rb

Overview

The module contains Path specific project methods, methods like name, path The module can be included into another module/class or used on it’s own, it does extend itself so any methods defined here is available to both class and instance level

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_path_part_cache =

Cache for project path parts 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

#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



46
47
48
49
50
51
52
# File 'lib/watch_tower/project/path_based.rb', line 46

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

  @@project_name_cache[path] = project_name_from_nested_path(code_path(options),
    path, nested_project_layers(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 (String)

    The path to look the project path from

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

    A hash of options

Returns:

  • (String)

    the project’s folder



32
33
34
35
36
37
38
39
# File 'lib/watch_tower/project/path_based.rb', line 32

def working_directory(path, options = {})
  return @@working_cache[path] if @@working_cache.key?(path)


  @@working_cache[path] = project_path_from_nested_path(code_path(options),
    path, nested_project_layers(options))
  @@working_cache[path]
end