Class: Glossarist::SchemaMigration
- Inherits:
-
Object
- Object
- Glossarist::SchemaMigration
- Defined in:
- lib/glossarist/schema_migration.rb
Constant Summary collapse
- CURRENT_SCHEMA_VERSION =
"1"- ENTRY_STATUS_MAP =
{ "Standard" => "valid", "Confirmed" => "valid", "Proposed" => "draft", }.freeze
- LANG_CODES =
Glossarist::LANG_CODES
- IEV_PATTERN =
/\{\{([^,}]+),\s*IEV:([^}]+)\}\}/.freeze
- URN_PATTERN =
/\{urn:iso:std:iso:(\d+):([^,}]+),([^}]+)\}/.freeze
Instance Attribute Summary collapse
-
#from_version ⇒ Object
readonly
Returns the value of attribute from_version.
-
#to_version ⇒ Object
readonly
Returns the value of attribute to_version.
Class Method Summary collapse
-
.upgrade_directory(source_dir, output:, target_version: CURRENT_SCHEMA_VERSION, cross_references: nil, dry_run: false) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/ParameterLists.
Instance Method Summary collapse
-
#initialize(concept_hash, from_version: "0", to_version: CURRENT_SCHEMA_VERSION, ref_maps: {}) ⇒ SchemaMigration
constructor
A new instance of SchemaMigration.
- #migrate ⇒ Object
Constructor Details
#initialize(concept_hash, from_version: "0", to_version: CURRENT_SCHEMA_VERSION, ref_maps: {}) ⇒ SchemaMigration
Returns a new instance of SchemaMigration.
22 23 24 25 26 27 28 |
# File 'lib/glossarist/schema_migration.rb', line 22 def initialize(concept_hash, from_version: "0", to_version: CURRENT_SCHEMA_VERSION, ref_maps: {}) @concept = concept_hash @from_version = from_version @to_version = to_version @ref_maps = ref_maps end |
Instance Attribute Details
#from_version ⇒ Object (readonly)
Returns the value of attribute from_version.
20 21 22 |
# File 'lib/glossarist/schema_migration.rb', line 20 def from_version @from_version end |
#to_version ⇒ Object (readonly)
Returns the value of attribute to_version.
20 21 22 |
# File 'lib/glossarist/schema_migration.rb', line 20 def to_version @to_version end |
Class Method Details
.upgrade_directory(source_dir, output:, target_version: CURRENT_SCHEMA_VERSION, cross_references: nil, dry_run: false) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/glossarist/schema_migration.rb', line 39 def self.upgrade_directory(source_dir, output:, # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists target_version: CURRENT_SCHEMA_VERSION, cross_references: nil, dry_run: false) source_dir = File.(source_dir) concepts_dir = find_concepts_dir(source_dir) unless File.directory?(source_dir) raise ArgumentError, "#{source_dir} is not a directory" end unless concepts_dir raise ArgumentError, "No concept YAML files found in #{source_dir}" end source_version = detect_schema_version(source_dir) ref_maps = load_ref_maps(cross_references) concepts = read_and_migrate_concepts(concepts_dir, source_version, target_version, ref_maps) register_data = read_register_yaml(source_dir, target_version) write_output(concepts, register_data, output, dry_run) { concepts: concepts, register_data: register_data, source_version: source_version, target_version: target_version, output: File.(output), count: concepts.length, } end |
Instance Method Details
#migrate ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/glossarist/schema_migration.rb', line 30 def migrate case [from_version, to_version] when ["0", "1"] then migrate_v0_to_v1 else raise Error, "Unsupported migration: #{from_version} -> #{to_version}" end @concept end |