Class: Unitsdb::Database::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/unitsdb/database/loader.rb

Overview

Filesystem and YAML-schema layer of Database. Reads the collection YAML files from a directory, validates their schema versions agree, and returns a combined hash ready for Lutaml::Model deserialization. Knows nothing about contexts or registers — that's Database.from_db's job.

Constant Summary collapse

DATABASE_FILES =
{
  "prefixes" => "prefixes.yaml",
  "dimensions" => "dimensions.yaml",
  "units" => "units.yaml",
  "quantities" => "quantities.yaml",
  "unit_systems" => "unit_systems.yaml",
}.freeze
SUPPORTED_SCHEMA_VERSION =
"2.0.0"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir_path) ⇒ Loader

Returns a new instance of Loader.



27
28
29
# File 'lib/unitsdb/database/loader.rb', line 27

def initialize(dir_path)
  @dir_path = File.expand_path(dir_path.to_s)
end

Class Method Details

.load(dir_path) ⇒ Object



23
24
25
# File 'lib/unitsdb/database/loader.rb', line 23

def self.load(dir_path)
  new(dir_path).load
end

Instance Method Details

#loadObject

Read every YAML file under @dir_path, validate schema versions, and return a combined hash keyed by collection name.



33
34
35
36
37
38
# File 'lib/unitsdb/database/loader.rb', line 33

def load
  verify_directory!
  documents = read_documents
  schema_version = validate_schema_versions!(documents)
  build_database_hash(documents, schema_version)
end