Class: RosettAi::ProjectContext
- Inherits:
-
Object
- Object
- RosettAi::ProjectContext
- Defined in:
- lib/rosett_ai/project_context.rb
Overview
Detects whether Dir.pwd is inside an rosett-ai-managed project by walking
up from the start directory looking for a .rosett-ai/ marker directory.
When found, content commands (design, behaviour, compile) resolve
their source paths relative to the project's .rosett-ai/ directory
instead of the Rosett-AI installation root.
Constant Summary collapse
- PROJECT_MARKER =
Directory name that marks the root of an rai project.
'.rosett-ai'
Instance Attribute Summary collapse
-
#project_root ⇒ Pathname?
readonly
Absolute path to the project root, or nil if no project detected.
Instance Method Summary collapse
-
#conf_root ⇒ Pathname
When inside the rosett-ai source tree, returns the source tree root (not
.rosett-ai/) so thatconf/resolves to the real configuration directory containing behaviour and design YAML files, rather than the empty.rosett-ai/conf/placeholder created byrai init --project. -
#initialize(start_dir: ENV.fetch('RAI_ORIGINAL_PWD', Dir.pwd)) ⇒ ProjectContext
constructor
A new instance of ProjectContext.
-
#project? ⇒ Boolean
True if a
.rosett-ai/marker was found. -
#project_conf_dir ⇒ Pathname
Path to the
conf/subdirectory for behaviour/design files. -
#rai_internal? ⇒ Boolean
True if the detected project is the Rosett-AI installation itself or the Rosett-AI source tree (when running the installed .deb from source).
Constructor Details
#initialize(start_dir: ENV.fetch('RAI_ORIGINAL_PWD', Dir.pwd)) ⇒ ProjectContext
Returns a new instance of ProjectContext.
23 24 25 |
# File 'lib/rosett_ai/project_context.rb', line 23 def initialize(start_dir: ENV.fetch('RAI_ORIGINAL_PWD', Dir.pwd)) @project_root = detect_project_root(start_dir) end |
Instance Attribute Details
#project_root ⇒ Pathname? (readonly)
Returns absolute path to the project root, or nil if no project detected.
18 19 20 |
# File 'lib/rosett_ai/project_context.rb', line 18 def project_root @project_root end |
Instance Method Details
#conf_root ⇒ Pathname
When inside the rosett-ai source tree, returns the source tree root (not .rosett-ai/)
so that conf/ resolves to the real configuration directory containing
behaviour and design YAML files, rather than the empty .rosett-ai/conf/
placeholder created by rai init --project.
44 45 46 47 48 |
# File 'lib/rosett_ai/project_context.rb', line 44 def conf_root return @project_root if rai_internal? project? ? @project_root.join(PROJECT_MARKER) : RosettAi.root end |
#project? ⇒ Boolean
Returns true if a .rosett-ai/ marker was found.
28 29 30 |
# File 'lib/rosett_ai/project_context.rb', line 28 def project? !@project_root.nil? end |
#project_conf_dir ⇒ Pathname
Returns path to the conf/ subdirectory for behaviour/design files.
51 52 53 |
# File 'lib/rosett_ai/project_context.rb', line 51 def project_conf_dir conf_root.join('conf') end |
#rai_internal? ⇒ Boolean
Returns true if the detected project is the Rosett-AI installation itself or the Rosett-AI source tree (when running the installed .deb from source).
34 35 36 |
# File 'lib/rosett_ai/project_context.rb', line 34 def rai_internal? @project_root == RosettAi.root || nncc_source_tree? end |