Class: Msnav::Config
- Inherits:
-
Object
- Object
- Msnav::Config
- Defined in:
- lib/msnav/config.rb
Overview
The slice of coderag.yml msnav needs: where the workspace is and where the index lives. Resolution mirrors coderag's load_config so both daemons agree on the db path for any given hub:
workspace_root: explicit arg > coderag.yml's key > "." (the cwd — the
lifecycle commands always run the daemon with cwd=hub)
storage_dir: declared (workspace-relative unless absolute)
> legacy <workspace>/.coderag when it already holds a db
> the package data dir (~/.local/share/coderag/hubs/<hub>)
All other coderag.yml keys (models, profiles, …) belong to the indexer and are ignored here — msnav never indexes.
Instance Attribute Summary collapse
-
#config_source ⇒ Object
readonly
Returns the value of attribute config_source.
-
#storage_dir ⇒ Object
readonly
Returns the value of attribute storage_dir.
-
#workspace_root ⇒ Object
readonly
Returns the value of attribute workspace_root.
Class Method Summary collapse
Instance Method Summary collapse
- #db_path ⇒ Object
-
#initialize(data, workspace_root: nil, source: nil) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(data, workspace_root: nil, source: nil) ⇒ Config
Returns a new instance of Config.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/msnav/config.rb', line 47 def initialize(data, workspace_root: nil, source: nil) @config_source = source root = workspace_root || data["workspace_root"] || "." @workspace_root = resolve(Pathname.new(File.(root.to_s))) declared = data["storage_dir"] if declared dir = Pathname.new(declared.to_s.sub(/\A~/) { Dir.home }) dir = @workspace_root + dir unless dir.absolute? @storage_dir = resolve(dir) else legacy = @workspace_root + ".coderag" @storage_dir = if (legacy + "coderag.db").exist? legacy else Datadir.hub_dir(@workspace_root) end end end |
Instance Attribute Details
#config_source ⇒ Object (readonly)
Returns the value of attribute config_source.
20 21 22 |
# File 'lib/msnav/config.rb', line 20 def config_source @config_source end |
#storage_dir ⇒ Object (readonly)
Returns the value of attribute storage_dir.
20 21 22 |
# File 'lib/msnav/config.rb', line 20 def storage_dir @storage_dir end |
#workspace_root ⇒ Object (readonly)
Returns the value of attribute workspace_root.
20 21 22 |
# File 'lib/msnav/config.rb', line 20 def workspace_root @workspace_root end |
Class Method Details
.load(path = nil, workspace_root: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/msnav/config.rb', line 22 def self.load(path = nil, workspace_root: nil) candidates = [] candidates << Pathname.new(path) if path env = ENV["CODERAG_CONFIG"] candidates << Pathname.new(env) if env && !env.empty? candidates << (Pathname.new(workspace_root) + "coderag.yml") if workspace_root candidates << Pathname.new("coderag.yml") data = {} source = nil candidates.each do |cand| next unless cand.file? begin data = YAML.safe_load(cand.read) || {} rescue Psych::SyntaxError => e raise ConfigError, "#{cand}: invalid YAML — #{e.}" end raise ConfigError, "#{cand}: top level must be a mapping" unless data.is_a?(Hash) source = cand. break end new(data, workspace_root: workspace_root, source: source) end |
Instance Method Details
#db_path ⇒ Object
67 68 69 |
# File 'lib/msnav/config.rb', line 67 def db_path @storage_dir + "coderag.db" end |