Class: RosettAi::Composition::ScopeResolver
- Inherits:
-
Object
- Object
- RosettAi::Composition::ScopeResolver
- Defined in:
- lib/rosett_ai/composition/scope_resolver.rb
Overview
Resolves the scope hierarchy for behaviour files. Scopes are ordered: global > organisation > project > local. Later scopes override earlier ones at equal priority.
Constant Summary collapse
- SCOPE_ORDER =
Ordered scope names from lowest to highest precedence.
['global', 'organisation', 'project', 'local'].freeze
- SCOPE_WEIGHTS =
Numeric weight for each scope (higher = takes precedence).
SCOPE_ORDER.each_with_index.to_h { |scope, i| [scope, i] }.freeze
Instance Method Summary collapse
-
#overrides?(scope_a, scope_b) ⇒ Boolean
Compares two scopes.
-
#resolve(file_path, project_root: nil) ⇒ String
Resolves the scope for a given behaviour file path.
-
#weight(scope) ⇒ Integer
Returns the numeric weight for a scope name.
Instance Method Details
#overrides?(scope_a, scope_b) ⇒ Boolean
Compares two scopes. Returns true if scope_a overrides scope_b.
50 51 52 |
# File 'lib/rosett_ai/composition/scope_resolver.rb', line 50 def overrides?(scope_a, scope_b) weight(scope_a) > weight(scope_b) end |
#resolve(file_path, project_root: nil) ⇒ String
Resolves the scope for a given behaviour file path.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rosett_ai/composition/scope_resolver.rb', line 23 def resolve(file_path, project_root: nil) path = file_path.to_s if project_root && path.start_with?(project_root.join('.rosett-ai', 'conf', 'behaviour').to_s) 'project' elsif path.include?('/organisation/') || path.include?('/org/') 'organisation' elsif path.include?('/local/') 'local' else 'global' end end |
#weight(scope) ⇒ Integer
Returns the numeric weight for a scope name.
41 42 43 |
# File 'lib/rosett_ai/composition/scope_resolver.rb', line 41 def weight(scope) SCOPE_WEIGHTS.fetch(scope, 0) end |