Class: Mnenv::VersionResolver
- Inherits:
-
Object
- Object
- Mnenv::VersionResolver
- Defined in:
- lib/mnenv/version_resolver.rb
Overview
Centralized version and source resolution with clear precedence:
-
Environment variables (METANORMA_VERSION, METANORMA_SOURCE)
-
Local files (.metanorma-version, .metanorma-source) - walk up tree
-
Global files (~/.mnenv/version, ~/.mnenv/source)
-
Defaults (gemfile for source)
This class is the single source of truth for version resolution. The Bash resolver (lib/mnenv/resolver) is kept for shims only.
Instance Method Summary collapse
-
#resolve ⇒ Array<String, String>
Resolve both version and source.
-
#resolve_source ⇒ String
Resolve the current Metanorma source.
-
#resolve_version ⇒ String?
Resolve the current Metanorma version.
-
#source_set? ⇒ Boolean
Check if a source is explicitly set (not default).
-
#source_source ⇒ Symbol
Get the source of source resolution (for debugging).
-
#version_set? ⇒ Boolean
Check if a version is set anywhere.
-
#version_source ⇒ Symbol
Get the source of version resolution (for debugging).
Instance Method Details
#resolve ⇒ Array<String, String>
Resolve both version and source
32 33 34 |
# File 'lib/mnenv/version_resolver.rb', line 32 def resolve [resolve_version, resolve_source] end |
#resolve_source ⇒ String
Resolve the current Metanorma source
23 24 25 26 27 28 |
# File 'lib/mnenv/version_resolver.rb', line 23 def resolve_source from_env('METANORMA_SOURCE') || from_local_file('.metanorma-source') || from_global_file(Paths::SOURCE_FILE) || 'gemfile' end |
#resolve_version ⇒ String?
Resolve the current Metanorma version
15 16 17 18 19 |
# File 'lib/mnenv/version_resolver.rb', line 15 def resolve_version from_env('METANORMA_VERSION') || from_local_file('.metanorma-version') || from_global_file(Paths::VERSION_FILE) end |
#source_set? ⇒ Boolean
Check if a source is explicitly set (not default)
44 45 46 47 48 |
# File 'lib/mnenv/version_resolver.rb', line 44 def source_set? from_env('METANORMA_SOURCE') || from_local_file('.metanorma-source') || from_global_file(Paths::SOURCE_FILE) end |
#source_source ⇒ Symbol
Get the source of source resolution (for debugging)
62 63 64 65 66 67 68 |
# File 'lib/mnenv/version_resolver.rb', line 62 def source_source return :environment if from_env('METANORMA_SOURCE') return :local if from_local_file('.metanorma-source') return :global if from_global_file(Paths::SOURCE_FILE) :default end |
#version_set? ⇒ Boolean
Check if a version is set anywhere
38 39 40 |
# File 'lib/mnenv/version_resolver.rb', line 38 def version_set? !resolve_version.nil? end |
#version_source ⇒ Symbol
Get the source of version resolution (for debugging)
52 53 54 55 56 57 58 |
# File 'lib/mnenv/version_resolver.rb', line 52 def version_source return :environment if from_env('METANORMA_VERSION') return :local if from_local_file('.metanorma-version') return :global if from_global_file(Paths::VERSION_FILE) :none end |