Module: Ucode::Audit::ReferenceFactory

Defined in:
lib/ucode/audit/reference_factory.rb

Overview

Translates CLI flags into a CoverageReference.

The audit CLI exposes the universal-set reference via a --reference-universal-set=<path> flag (and a default lookup at output/universal_glyph_set/manifest.json). This factory resolves the flag value into a concrete reference instance backed by a freshly-opened Database, so the command classes don't repeat the same branching.

Behavior:

  • flag = "none" → nil (force UCD-only even if a default manifest exists)
  • flag = path to .json → UniversalSetReference
  • flag = nil → look at DEFAULT_MANIFEST_PATH; use it if present, else nil (UCD-only)

Lives in the Ucode::Audit namespace (not Commands::Audit) so the Audit module owns its own entry point — programmatic callers don't need to round-trip through the CLI to obtain a reference.

Constant Summary collapse

DEFAULT_MANIFEST_PATH =
Pathname.new("output/universal_glyph_set/manifest.json")

Class Method Summary collapse

Class Method Details

.build_from_cli(flag:, version: nil) ⇒ Ucode::Audit::CoverageReference?

Parameters:

  • flag (String, nil)

    value of the --reference-universal-set CLI option.

  • version (String, nil) (defaults to: nil)

    UCD version for the database that backs the reference. When nil, the default UCD version is resolved.

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ucode/audit/reference_factory.rb', line 37

def build_from_cli(flag:, version: nil)
  return nil if flag == "none"

  path = resolve_manifest_path(flag)
  return nil unless path && File.exist?(path)

  database = open_database(version)
  return nil unless database

  Ucode::Audit::UniversalSetReference.new(
    manifest: path, database: database,
  )
end

.open_database(version) ⇒ Object



58
59
60
61
62
63
# File 'lib/ucode/audit/reference_factory.rb', line 58

def open_database(version)
  resolved = version || Ucode::VersionResolver.resolve(nil)
  Ucode::Database.open(resolved)
rescue Ucode::UnknownVersionError, Ucode::DatabaseMissingError
  nil
end

.resolve_manifest_path(flag) ⇒ Object



51
52
53
54
55
56
# File 'lib/ucode/audit/reference_factory.rb', line 51

def resolve_manifest_path(flag)
  return Pathname.new(flag) if flag && flag != "none"
  return DEFAULT_MANIFEST_PATH if DEFAULT_MANIFEST_PATH.exist?

  nil
end