Class: Rwm::Workspace

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#rootObject (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

Raises:



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.expand_path(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_pathObject



32
33
34
# File 'lib/rwm/workspace.rb', line 32

def graph_path
  File.join(rwm_dir, GRAPH_FILE)
end

#packagesObject

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_dirObject



28
29
30
# File 'lib/rwm/workspace.rb', line 28

def rwm_dir
  File.join(root, RWM_DIR)
end