Class: Rwm::Workspace
- Inherits:
-
Object
- Object
- Rwm::Workspace
- Defined in:
- lib/rwm/workspace.rb
Constant Summary collapse
- RWM_DIR =
".rwm"- PACKAGE_DIRS =
%w[libs apps].freeze
- GRAPH_FILE =
"graph.json"
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
-
.find(start_dir = Dir.pwd) ⇒ Object
Find the workspace root via git.
Instance Method Summary collapse
- #find_package(name) ⇒ Object
- #graph_path ⇒ Object
-
#initialize(root) ⇒ Workspace
constructor
A new instance of Workspace.
-
#packages ⇒ Object
Discover all packages by scanning libs/ and apps/ for directories with a Gemfile.
- #rwm_dir ⇒ Object
Constructor Details
#initialize(root) ⇒ Workspace
Returns a new instance of Workspace.
13 14 15 |
# File 'lib/rwm/workspace.rb', line 13 def initialize(root) @root = root end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
11 12 13 |
# File 'lib/rwm/workspace.rb', line 11 def root @root end |
Class Method Details
.find(start_dir = Dir.pwd) ⇒ Object
Find the workspace root via git
18 19 20 21 22 23 24 25 26 |
# File 'lib/rwm/workspace.rb', line 18 def self.find(start_dir = Dir.pwd) dir = File.(start_dir) git_root, _, status = Open3.capture3("git", "-C", dir, "rev-parse", "--show-toplevel") git_root = status.success? ? git_root.chomp : "" raise WorkspaceNotFoundError if git_root.empty? new(git_root) end |
Instance Method Details
#find_package(name) ⇒ Object
41 42 43 |
# File 'lib/rwm/workspace.rb', line 41 def find_package(name) packages.find { |p| p.name == name } || raise(PackageNotFoundError, name) end |
#graph_path ⇒ Object
32 33 34 |
# File 'lib/rwm/workspace.rb', line 32 def graph_path File.join(rwm_dir, GRAPH_FILE) end |
#packages ⇒ Object
Discover all packages by scanning libs/ and apps/ for directories with a Gemfile
37 38 39 |
# File 'lib/rwm/workspace.rb', line 37 def packages @packages ||= discover_packages end |
#rwm_dir ⇒ Object
28 29 30 |
# File 'lib/rwm/workspace.rb', line 28 def rwm_dir File.join(root, RWM_DIR) end |