Class: MTBuild::BuildRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/mtbuild/build_registry.rb

Overview

This class holds the mtbuild workspace hierarchy

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.active_workspaceObject (readonly)

The top-level workspace



25
26
27
# File 'lib/mtbuild/build_registry.rb', line 25

def active_workspace
  @active_workspace
end

.projectsObject (readonly)

The map of registered projects



19
20
21
# File 'lib/mtbuild/build_registry.rb', line 19

def projects
  @projects
end

.top_workspaceObject (readonly)

The top-level workspace



22
23
24
# File 'lib/mtbuild/build_registry.rb', line 22

def top_workspace
  @top_workspace
end

.workspacesObject (readonly)

The map of registered workspaces



16
17
18
# File 'lib/mtbuild/build_registry.rb', line 16

def workspaces
  @workspaces
end

Class Method Details

.enter_project(project_name, project) ⇒ Object

Track the beginning of a new project’s creation



51
52
53
54
55
56
57
# File 'lib/mtbuild/build_registry.rb', line 51

def enter_project(project_name, project)
  project_name = self.hierarchical_name(project_name)
  self.found_project(project_name)
  fail "A project named #{project_name} was already added." if @projects.has_key?(project_name)
  @projects[project_name] = project
  return project_name, @active_workspace
end

.enter_workspace(workspace_name, workspace) ⇒ Object

Track the beginning of a new workspace’s creation



28
29
30
31
32
33
34
35
36
37
# File 'lib/mtbuild/build_registry.rb', line 28

def enter_workspace(workspace_name, workspace)
  workspace_name = self.hierarchical_name(workspace_name)
  self.found_workspace(workspace_name)
  fail "A workspace named #{workspace_name} was already added." if @workspaces.has_key?(workspace_name)
  @workspaces[workspace_name] = workspace
  @top_workspace = workspace if @top_workspace.nil?
  parent = @active_workspace
  @active_workspace = workspace
  return workspace_name, parent
end

.exit_projectObject

Track the completion of a new project’s creation



60
61
# File 'lib/mtbuild/build_registry.rb', line 60

def exit_project
end

.exit_workspaceObject

Track the completion of a new workspace’s creation



47
48
# File 'lib/mtbuild/build_registry.rb', line 47

def exit_workspace
end

.expect_projectObject

Register that we next expect to encounter a project, not a workspace



70
71
72
73
# File 'lib/mtbuild/build_registry.rb', line 70

def expect_project
  # We expect an explicitly-added project.
  @expecting=:added_project
end

.expect_workspaceObject

Register that we next expect to encounter a workspace, not a project



64
65
66
67
# File 'lib/mtbuild/build_registry.rb', line 64

def expect_workspace
  # We expect an explicitly-added workspace.
  @expecting=:added_workspace
end

.found_project(project_name) ⇒ Object

Register that we encountered a project and verify that it’s allowed



86
87
88
89
90
91
92
# File 'lib/mtbuild/build_registry.rb', line 86

def found_project(project_name)
  unless [:project_or_workspace, :project, :added_project].include? @expecting
    fail "#{project_name} was added with add_workspace(), but it contains a project. Use add_project() if you want to include it." if @expecting==:added_workspace
  end
  # We expect nothing but top-level projects now.
  @expecting=:project
end

.found_workspace(workspace_name) ⇒ Object

Register that we encountered a workspace and verify that it’s allowed



76
77
78
79
80
81
82
83
# File 'lib/mtbuild/build_registry.rb', line 76

def found_workspace(workspace_name)
  unless [:project_or_workspace, :added_workspace].include? @expecting
    fail "#{workspace_name} was added with add_project(), but it contains a workspace. Use add_workspace() if you want to include it." if @expecting==:added_project
    fail "Encountered workspace #{workspace_name} declared after a project or another workspace in the same file. This isn't allowed."
  end
  # We expect nothing but top-level projects now.
  @expecting=:project
end

.hierarchical_name(name) ⇒ Object

Get a workspace/project name that reflects the workspace/project hierarchy



95
96
97
98
# File 'lib/mtbuild/build_registry.rb', line 95

def hierarchical_name(name)
  return name if @active_workspace.nil?
  "#{@active_workspace.workspace_name}:#{name}"
end

.reenter_workspace(workspace) ⇒ Object

Track the re-entry into a parent workspace after importing a child workspace.



40
41
42
43
44
# File 'lib/mtbuild/build_registry.rb', line 40

def reenter_workspace(workspace)
  last_workspace = @active_workspace
  @active_workspace = workspace
  last_workspace
end