Class: Mnenv::VersionResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/mnenv/version_resolver.rb

Overview

Centralized version and source resolution with clear precedence:

  1. Environment variables (METANORMA_VERSION, METANORMA_SOURCE)

  2. Local files (.metanorma-version, .metanorma-source) - walk up tree

  3. Global files (~/.mnenv/version, ~/.mnenv/source)

  4. 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

Instance Method Details

#resolveArray<String, String>

Resolve both version and source

Returns:

  • (Array<String, String>)

    Tuple of [version, source]



32
33
34
# File 'lib/mnenv/version_resolver.rb', line 32

def resolve
  [resolve_version, resolve_source]
end

#resolve_sourceString

Resolve the current Metanorma source

Returns:

  • (String)

    The resolved source (defaults to ‘gemfile’)



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_versionString?

Resolve the current Metanorma version

Returns:

  • (String, nil)

    The resolved version or nil if not set



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)

Returns:

  • (Boolean)


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_sourceSymbol

Get the source of source resolution (for debugging)

Returns:

  • (Symbol)

    :environment, :local, :global, or :default



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

Returns:

  • (Boolean)


38
39
40
# File 'lib/mnenv/version_resolver.rb', line 38

def version_set?
  !resolve_version.nil?
end

#version_sourceSymbol

Get the source of version resolution (for debugging)

Returns:

  • (Symbol)

    :environment, :local, :global, or :none



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