Class: Glossarist::SchemaMigration

Inherits:
Object
  • Object
show all
Defined in:
lib/glossarist/schema_migration.rb,
lib/glossarist/schema_migration/v0_to_v1.rb,
lib/glossarist/schema_migration/v2_to_v3.rb

Defined Under Namespace

Modules: V2ToV3 Classes: V0ToV1

Constant Summary collapse

CURRENT_SCHEMA_VERSION =
"1"

Class Method Summary collapse

Class Method Details

.concept_version(concept) ⇒ Object



20
21
22
# File 'lib/glossarist/schema_migration.rb', line 20

def self.concept_version(concept)
  V2ToV3.concept_version(concept)
end

.migrate_concept(concept, target_version: Glossarist::SCHEMA_VERSION) ⇒ Object



16
17
18
# File 'lib/glossarist/schema_migration.rb', line 16

def self.migrate_concept(concept, target_version: Glossarist::SCHEMA_VERSION)
  V2ToV3.migrate_concept(concept, target_version: target_version)
end

.newObject



12
13
14
# File 'lib/glossarist/schema_migration.rb', line 12

def self.new(...)
  V0ToV1.new(...)
end

.upgrade_directory(source_dir, output:, target_version: CURRENT_SCHEMA_VERSION, cross_references: nil, dry_run: false) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/ParameterLists



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/glossarist/schema_migration.rb', line 24

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.expand_path(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.expand_path(output),
    count: concepts.length,
  }
end