unitsdb 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +15 -92
- data/Gemfile +0 -1
- data/README.adoc +2 -108
- data/lib/unitsdb/cli.rb +0 -7
- data/lib/unitsdb/commands/_modify.rb +2 -2
- data/lib/unitsdb/commands/base.rb +33 -7
- data/lib/unitsdb/commands/normalize.rb +1 -1
- data/lib/unitsdb/commands/release.rb +86 -47
- data/lib/unitsdb/commands/validate/identifiers.rb +1 -3
- data/lib/unitsdb/commands/validate/references.rb +1 -3
- data/lib/unitsdb/commands/validate/si_references.rb +6 -0
- data/lib/unitsdb/commands/validate.rb +3 -3
- data/lib/unitsdb/database.rb +0 -1
- data/lib/unitsdb/dimensions.rb +0 -1
- data/lib/unitsdb/prefixes.rb +0 -1
- data/lib/unitsdb/quantities.rb +0 -1
- data/lib/unitsdb/scales.rb +0 -1
- data/lib/unitsdb/unit_systems.rb +0 -1
- data/lib/unitsdb/units.rb +0 -1
- data/lib/unitsdb/version.rb +1 -1
- data/unitsdb.gemspec +2 -0
- metadata +2 -10
- data/lib/unitsdb/commands/ucum/check.rb +0 -126
- data/lib/unitsdb/commands/ucum/formatter.rb +0 -141
- data/lib/unitsdb/commands/ucum/matcher.rb +0 -301
- data/lib/unitsdb/commands/ucum/update.rb +0 -84
- data/lib/unitsdb/commands/ucum/updater.rb +0 -98
- data/lib/unitsdb/commands/ucum/xml_parser.rb +0 -34
- data/lib/unitsdb/commands/ucum.rb +0 -43
- data/lib/unitsdb/ucum.rb +0 -198
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b92f561a56f8cdd59a905cf7827c6ffda47acae64f1e31256f2c5efebfd81f2
|
4
|
+
data.tar.gz: 218a47cf5fb2c178f787f05e186c09f5b40d0f4914b81d6de5884759011621ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82bd1ac58073379426b3378bda8b94e0bcdf46f954148d082b6008931d0c49c0c50d35b53ac64661a75e0f58bfedf46a5f53e0e948e5520584711a0260ebe638
|
7
|
+
data.tar.gz: ff4538f70410cc9572f7a7719bf32aa1324f6e2cdaf7fe95acbd6426b31168b9c4ba72271d81fe8a76dd1339aa0d3d3307424a878b4cb11e96be5af9897078b0
|
data/.rubocop_todo.yml
CHANGED
@@ -1,56 +1,17 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2025-05-
|
3
|
+
# on 2025-05-20 11:22:36 UTC using RuboCop version 1.75.6.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
9
|
# Offense count: 1
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
Layout/ArrayAlignment:
|
14
|
-
Exclude:
|
15
|
-
- 'lib/unitsdb/commands/ucum/check.rb'
|
16
|
-
|
17
|
-
# Offense count: 1
|
18
|
-
# This cop supports safe autocorrection (--autocorrect).
|
19
|
-
# Configuration parameters: AutoCorrect, AllowBorderComment, AllowMarginComment.
|
20
|
-
Layout/EmptyComment:
|
21
|
-
Exclude:
|
22
|
-
- 'ucum-test.rb'
|
23
|
-
|
24
|
-
# Offense count: 1
|
25
|
-
# This cop supports safe autocorrection (--autocorrect).
|
26
|
-
Layout/EmptyLineAfterMagicComment:
|
27
|
-
Exclude:
|
28
|
-
- 'ucum-test.rb'
|
29
|
-
|
30
|
-
# Offense count: 4
|
31
|
-
# This cop supports safe autocorrection (--autocorrect).
|
32
|
-
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
|
33
|
-
# SupportedHashRocketStyles: key, separator, table
|
34
|
-
# SupportedColonStyles: key, separator, table
|
35
|
-
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
|
36
|
-
Layout/HashAlignment:
|
37
|
-
Exclude:
|
38
|
-
- 'spec/unitsdb/commands/ucum/update_spec.rb'
|
39
|
-
|
40
|
-
# Offense count: 5
|
41
|
-
# This cop supports safe autocorrection (--autocorrect).
|
42
|
-
# Configuration parameters: AllowInHeredoc.
|
43
|
-
Layout/TrailingWhitespace:
|
44
|
-
Exclude:
|
45
|
-
- 'lib/unitsdb/commands/ucum/check.rb'
|
46
|
-
- 'spec/unitsdb/commands/ucum/update_spec.rb'
|
47
|
-
|
48
|
-
# Offense count: 1
|
49
|
-
# This cop supports unsafe autocorrection (--autocorrect-all).
|
50
|
-
# Configuration parameters: AllowSafeAssignment.
|
51
|
-
Lint/AssignmentInCondition:
|
10
|
+
# Configuration parameters: Severity, Include.
|
11
|
+
# Include: **/*.gemspec
|
12
|
+
Gemspec/DuplicatedAssignment:
|
52
13
|
Exclude:
|
53
|
-
- '
|
14
|
+
- 'unitsdb.gemspec'
|
54
15
|
|
55
16
|
# Offense count: 2
|
56
17
|
Lint/ShadowingOuterLocalVariable:
|
@@ -58,12 +19,12 @@ Lint/ShadowingOuterLocalVariable:
|
|
58
19
|
- 'lib/unitsdb/commands/search.rb'
|
59
20
|
- 'lib/unitsdb/commands/validate/si_references.rb'
|
60
21
|
|
61
|
-
# Offense count:
|
22
|
+
# Offense count: 37
|
62
23
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
63
24
|
Metrics/AbcSize:
|
64
25
|
Max: 169
|
65
26
|
|
66
|
-
# Offense count:
|
27
|
+
# Offense count: 27
|
67
28
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
68
29
|
# AllowedMethods: refine
|
69
30
|
Metrics/BlockLength:
|
@@ -72,19 +33,19 @@ Metrics/BlockLength:
|
|
72
33
|
# Offense count: 3
|
73
34
|
# Configuration parameters: CountComments, CountAsOne.
|
74
35
|
Metrics/ClassLength:
|
75
|
-
Max:
|
36
|
+
Max: 441
|
76
37
|
|
77
|
-
# Offense count:
|
38
|
+
# Offense count: 38
|
78
39
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
79
40
|
Metrics/CyclomaticComplexity:
|
80
41
|
Max: 50
|
81
42
|
|
82
|
-
# Offense count:
|
43
|
+
# Offense count: 47
|
83
44
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
84
45
|
Metrics/MethodLength:
|
85
46
|
Max: 169
|
86
47
|
|
87
|
-
# Offense count:
|
48
|
+
# Offense count: 3
|
88
49
|
# Configuration parameters: CountComments, CountAsOne.
|
89
50
|
Metrics/ModuleLength:
|
90
51
|
Max: 369
|
@@ -94,7 +55,7 @@ Metrics/ModuleLength:
|
|
94
55
|
Metrics/ParameterLists:
|
95
56
|
Max: 6
|
96
57
|
|
97
|
-
# Offense count:
|
58
|
+
# Offense count: 33
|
98
59
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
99
60
|
Metrics/PerceivedComplexity:
|
100
61
|
Max: 56
|
@@ -112,45 +73,17 @@ Naming/MethodParameterName:
|
|
112
73
|
- 'lib/unitsdb/commands/si_ttl_parser.rb'
|
113
74
|
- 'lib/unitsdb/utils.rb'
|
114
75
|
|
115
|
-
# Offense count: 1
|
116
|
-
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros, UseSorbetSigs.
|
117
|
-
# NamePrefix: is_, has_, have_, does_
|
118
|
-
# ForbiddenPrefixes: is_, has_, have_, does_
|
119
|
-
# AllowedMethods: is_a?
|
120
|
-
# MethodDefinitionMacros: define_method, define_singleton_method
|
121
|
-
Naming/PredicateName:
|
122
|
-
Exclude:
|
123
|
-
- 'spec/**/*'
|
124
|
-
- 'lib/unitsdb/commands/ucum/matcher.rb'
|
125
|
-
|
126
76
|
# Offense count: 1
|
127
77
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
128
78
|
Style/CombinableLoops:
|
129
79
|
Exclude:
|
130
80
|
- 'lib/unitsdb/commands/si_matcher.rb'
|
131
81
|
|
132
|
-
# Offense count:
|
82
|
+
# Offense count: 40
|
133
83
|
# Configuration parameters: AllowedConstants.
|
134
84
|
Style/Documentation:
|
135
85
|
Enabled: false
|
136
86
|
|
137
|
-
# Offense count: 1
|
138
|
-
# This cop supports safe autocorrection (--autocorrect).
|
139
|
-
# Configuration parameters: AutoCorrect, EnforcedStyle, AllowComments.
|
140
|
-
# SupportedStyles: empty, nil, both
|
141
|
-
Style/EmptyElse:
|
142
|
-
Exclude:
|
143
|
-
- 'lib/unitsdb/commands/ucum/updater.rb'
|
144
|
-
|
145
|
-
# Offense count: 1
|
146
|
-
# This cop supports unsafe autocorrection (--autocorrect-all).
|
147
|
-
# Configuration parameters: EnforcedStyle.
|
148
|
-
# SupportedStyles: always, always_true, never
|
149
|
-
Style/FrozenStringLiteralComment:
|
150
|
-
Exclude:
|
151
|
-
- '**/*.arb'
|
152
|
-
- 'ucum-test.rb'
|
153
|
-
|
154
87
|
# Offense count: 2
|
155
88
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
156
89
|
Style/IdenticalConditionalBranches:
|
@@ -162,25 +95,15 @@ Style/MultilineBlockChain:
|
|
162
95
|
Exclude:
|
163
96
|
- 'lib/unitsdb/commands/normalize.rb'
|
164
97
|
|
165
|
-
# Offense count:
|
98
|
+
# Offense count: 5
|
166
99
|
# Configuration parameters: AllowedMethods.
|
167
100
|
# AllowedMethods: respond_to_missing?
|
168
101
|
Style/OptionalBooleanParameter:
|
169
102
|
Exclude:
|
170
103
|
- 'lib/unitsdb/commands/check_si.rb'
|
171
104
|
- 'lib/unitsdb/commands/si_updater.rb'
|
172
|
-
- 'lib/unitsdb/commands/ucum/check.rb'
|
173
|
-
- 'lib/unitsdb/commands/ucum/updater.rb'
|
174
|
-
|
175
|
-
# Offense count: 7
|
176
|
-
# This cop supports unsafe autocorrection (--autocorrect-all).
|
177
|
-
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
|
178
|
-
# AllowedMethods: present?, blank?, presence, try, try!
|
179
|
-
Style/SafeNavigation:
|
180
|
-
Exclude:
|
181
|
-
- 'lib/unitsdb/commands/ucum/matcher.rb'
|
182
105
|
|
183
|
-
# Offense count:
|
106
|
+
# Offense count: 6
|
184
107
|
# This cop supports safe autocorrection (--autocorrect).
|
185
108
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
186
109
|
# URISchemes: http, https
|
data/Gemfile
CHANGED
data/README.adoc
CHANGED
@@ -101,7 +101,6 @@ Syntax:
|
|
101
101
|
[source,yaml]
|
102
102
|
----
|
103
103
|
schema_version: 2.0.0
|
104
|
-
version: 1.0.0 # Release version (in semantic format x.y.z)
|
105
104
|
dimensions:
|
106
105
|
- identifiers: [...]
|
107
106
|
length: {...}
|
@@ -270,7 +269,7 @@ Options:
|
|
270
269
|
|
271
270
|
`--all`, `-a`:: Process all YAML files in the repository
|
272
271
|
`--database`, `-d`:: Path to UnitsDB database (required)
|
273
|
-
`--sort`:: Sort units by: 'short' (name), 'nist' (ID
|
272
|
+
`--sort`:: Sort units by: 'short' (name, default), 'nist' (ID), 'unitsml' (ID), or 'none'
|
274
273
|
|
275
274
|
|
276
275
|
==== Search
|
@@ -384,108 +383,6 @@ with added SI references
|
|
384
383
|
`--include-potential-matches`, `-p`:: Include potential matches when updating
|
385
384
|
references (default: false)
|
386
385
|
|
387
|
-
|
388
|
-
==== Check references to UCUM
|
389
|
-
|
390
|
-
Performs a comprehensive check of entities in the UCUM XML file against UnitsDB
|
391
|
-
database entities and updates UnitsDB with UCUM references.
|
392
|
-
|
393
|
-
UCUM supports the following entity types:
|
394
|
-
|
395
|
-
* Base units
|
396
|
-
* Units
|
397
|
-
* Prefixes
|
398
|
-
|
399
|
-
UCUM provides dimensions as part of their unit definitions but not as
|
400
|
-
uniquely referencable entities.
|
401
|
-
|
402
|
-
This combined command checks in both directions to ensure UnitsDB supports
|
403
|
-
every UCUM entity:
|
404
|
-
|
405
|
-
* From UCUM to UnitsDB: Ensures every UCUM entity is referenced by at least one
|
406
|
-
UnitsDB entity
|
407
|
-
|
408
|
-
* From UnitsDB to UCUM: Identifies UnitsDB entities that should reference UCUM
|
409
|
-
entities
|
410
|
-
|
411
|
-
There are two commands:
|
412
|
-
|
413
|
-
* `ucum check`: Checks for matches between UnitsDB and UCUM entities and reports results
|
414
|
-
|
415
|
-
* `ucum update`: Updates UnitsDB entities with references to matching UCUM entities
|
416
|
-
|
417
|
-
[source,sh]
|
418
|
-
----
|
419
|
-
# Check all entity types and generate a report
|
420
|
-
$ unitsdb ucum check --database=spec/fixtures/unitsdb --ucum-file=spec/fixtures/ucum/ucum-essence.xml
|
421
|
-
|
422
|
-
# Check a specific entity type (units or prefixes)
|
423
|
-
$ unitsdb ucum check --entity-type=units \
|
424
|
-
--database=spec/fixtures/unitsdb \
|
425
|
-
--ucum-file=spec/fixtures/ucum/ucum-essence.xml
|
426
|
-
|
427
|
-
# Check in a specific direction only
|
428
|
-
$ unitsdb ucum check --direction=from_ucum \
|
429
|
-
--database=spec/fixtures/unitsdb \
|
430
|
-
--ucum-file=spec/fixtures/ucum/ucum-essence.xml
|
431
|
-
----
|
432
|
-
|
433
|
-
Options:
|
434
|
-
|
435
|
-
`--database`, `-d`:: Path to UnitsDB database (required)
|
436
|
-
|
437
|
-
`--ucum-file`, `-u`:: Path to the UCUM essence XML file (required)
|
438
|
-
|
439
|
-
`--entity-type`, `-e`:: Entity type to check (units or prefixes).
|
440
|
-
If not specified, all types are checked.
|
441
|
-
|
442
|
-
`--direction`, `-r`:: Direction to check: `to_ucum` (UnitsDB→UCUM), `from_ucum`
|
443
|
-
(UCUM→UnitsDB), or `both` (default)
|
444
|
-
|
445
|
-
`--output-updated-database`, `-o`:: Directory path to write updated YAML files
|
446
|
-
with added UCUM references
|
447
|
-
|
448
|
-
`--include-potential-matches`, `-p`:: Include potential matches when updating
|
449
|
-
references (default: false)
|
450
|
-
|
451
|
-
|
452
|
-
==== Update UCUM references
|
453
|
-
|
454
|
-
[source,sh]
|
455
|
-
----
|
456
|
-
# Update all entity types with UCUM references
|
457
|
-
$ unitsdb ucum update --database=spec/fixtures/unitsdb \
|
458
|
-
--ucum-file=spec/fixtures/ucum/ucum-essence.xml \
|
459
|
-
--output-dir=new_unitsdb
|
460
|
-
|
461
|
-
# Update a specific entity type (units or prefixes)
|
462
|
-
$ unitsdb ucum update --entity-type=units \
|
463
|
-
--database=spec/fixtures/unitsdb \
|
464
|
-
--ucum-file=spec/fixtures/ucum/ucum-essence.xml \
|
465
|
-
--output-dir=new_unitsdb
|
466
|
-
|
467
|
-
# Include potential matches when updating references (default: false)
|
468
|
-
$ unitsdb ucum update --include-potential-matches \
|
469
|
-
--database=spec/fixtures/unitsdb \
|
470
|
-
--ucum-file=spec/fixtures/ucum/ucum-essence.xml \
|
471
|
-
--output-dir=new_unitsdb
|
472
|
-
----
|
473
|
-
|
474
|
-
Options:
|
475
|
-
|
476
|
-
`--database`, `-d`:: Path to UnitsDB database (required)
|
477
|
-
|
478
|
-
`--ucum-file`, `-u`:: Path to the UCUM essence XML file (required)
|
479
|
-
|
480
|
-
`--entity-type`, `-e`:: Entity type to update (units or prefixes).
|
481
|
-
If not specified, all types are updated
|
482
|
-
|
483
|
-
`--output-dir`, `-o`:: Directory path to write updated YAML files
|
484
|
-
(defaults to database path)
|
485
|
-
|
486
|
-
`--include-potential-matches`, `-p`:: Include potential matches when updating
|
487
|
-
references (default: false)
|
488
|
-
|
489
386
|
==== Release
|
490
387
|
|
491
388
|
Creates release files for UnitsDB in unified formats:
|
@@ -503,9 +400,6 @@ $ unitsdb release --format=zip --database=/path/to/unitsdb/data
|
|
503
400
|
|
504
401
|
# Specify output directory
|
505
402
|
$ unitsdb release --output-dir=/path/to/output --database=/path/to/unitsdb/data
|
506
|
-
|
507
|
-
# Specify a version (required)
|
508
|
-
$ unitsdb release --version=2.1.0 --database=/path/to/unitsdb/data
|
509
403
|
----
|
510
404
|
|
511
405
|
This command creates release files for UnitsDB in two formats:
|
@@ -516,7 +410,7 @@ This command creates release files for UnitsDB in two formats:
|
|
516
410
|
|
517
411
|
The command verifies that all files have the same schema version before creating
|
518
412
|
the release files. The output files are named with the schema version (e.g.,
|
519
|
-
`unitsdb-2.
|
413
|
+
`unitsdb-2.0.0.yaml` and `unitsdb-2.0.0.zip`).
|
520
414
|
|
521
415
|
Options:
|
522
416
|
|
data/lib/unitsdb/cli.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "thor"
|
4
|
-
require_relative "commands/base"
|
5
4
|
require_relative "commands/validate"
|
6
5
|
require_relative "commands/_modify"
|
7
|
-
require_relative "commands/ucum"
|
8
6
|
require "fileutils"
|
9
7
|
|
10
8
|
module Unitsdb
|
@@ -14,9 +12,6 @@ module Unitsdb
|
|
14
12
|
true
|
15
13
|
end
|
16
14
|
|
17
|
-
desc "ucum SUBCOMMAND", "UCUM-related commands"
|
18
|
-
subcommand "ucum", Commands::UcumCommand
|
19
|
-
|
20
15
|
desc "_modify SUBCOMMAND", "Commands that modify the database"
|
21
16
|
subcommand "_modify", Commands::ModifyCommand
|
22
17
|
|
@@ -76,8 +71,6 @@ module Unitsdb
|
|
76
71
|
desc: "Output format: 'yaml' (single file), 'zip' (archive), or 'all' (both)"
|
77
72
|
option :output_dir, type: :string, default: ".", aliases: "-o",
|
78
73
|
desc: "Directory to output release files"
|
79
|
-
option :version, type: :string, aliases: "-v", required: true,
|
80
|
-
desc: "Version number for the release (x.y.z)"
|
81
74
|
option :database, type: :string, required: true, aliases: "-d",
|
82
75
|
desc: "Path to UnitsDB database (required)"
|
83
76
|
def release
|
@@ -6,8 +6,8 @@ module Unitsdb
|
|
6
6
|
module Commands
|
7
7
|
class ModifyCommand < Thor
|
8
8
|
desc "normalize [INPUT] [OUTPUT]", "Normalize a YAML file or all YAML files with --all"
|
9
|
-
method_option :sort, type: :string, default: "
|
10
|
-
desc: "Sort units by: 'short' (name), 'nist' (ID
|
9
|
+
method_option :sort, type: :string, default: "short",
|
10
|
+
desc: "Sort units by: 'short' (name), 'nist' (ID), 'unitsml' (ID), or 'none'"
|
11
11
|
method_option :database, type: :string, required: true, aliases: "-d",
|
12
12
|
desc: "Path to UnitsDB database (required)"
|
13
13
|
method_option :all, type: :boolean, default: false, aliases: "-a",
|
@@ -1,25 +1,51 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "thor"
|
3
4
|
require "yaml"
|
4
|
-
|
5
|
+
require_relative "../utils"
|
6
|
+
require_relative "../database"
|
5
7
|
|
6
8
|
module Unitsdb
|
7
9
|
module Commands
|
8
10
|
class Base
|
9
11
|
def initialize(options = {})
|
10
12
|
@options = options
|
11
|
-
puts "Database directory path: #{@options[:database]}" if @options[:database]
|
12
13
|
end
|
13
14
|
|
14
15
|
protected
|
15
16
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
17
|
+
def yaml_files(input = nil, opts = nil)
|
18
|
+
options_to_use = opts || @options
|
19
|
+
|
20
|
+
if options_to_use[:all]
|
21
|
+
Unitsdb::Utils::DEFAULT_YAML_FILES.map { |f| File.join(options_to_use[:database], f) }
|
22
|
+
elsif input
|
23
|
+
[input]
|
24
|
+
else
|
25
|
+
puts "Error: INPUT file is required when not using --all"
|
26
|
+
exit(1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_database(database_path = nil)
|
31
|
+
path = database_path || @options[:database]
|
32
|
+
|
33
|
+
raise Unitsdb::Errors::DatabaseError, "Database path must be specified using the --database option" if path.nil?
|
19
34
|
|
20
35
|
Unitsdb::Database.from_db(path)
|
21
|
-
rescue
|
22
|
-
|
36
|
+
rescue Unitsdb::Errors::DatabaseError => e
|
37
|
+
puts "Error: #{e.message}"
|
38
|
+
exit(1)
|
39
|
+
end
|
40
|
+
|
41
|
+
def load_yaml(file_path)
|
42
|
+
return nil unless File.exist?(file_path)
|
43
|
+
|
44
|
+
YAML.safe_load(File.read(file_path))
|
45
|
+
end
|
46
|
+
|
47
|
+
def file_type(file_path)
|
48
|
+
File.basename(file_path, ".yaml")
|
23
49
|
end
|
24
50
|
end
|
25
51
|
end
|
@@ -33,7 +33,7 @@ module Unitsdb
|
|
33
33
|
|
34
34
|
def normalize_file(input, output)
|
35
35
|
# Load the original YAML to work with
|
36
|
-
yaml =
|
36
|
+
yaml = load_yaml(input)
|
37
37
|
|
38
38
|
# For schema 2.0.0, we need to handle the schema_version and the main collection key
|
39
39
|
if yaml.key?("schema_version") && yaml["schema_version"] == "2.0.0"
|
@@ -1,72 +1,111 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "base"
|
3
4
|
require "yaml"
|
4
5
|
require "zip"
|
5
6
|
require "fileutils"
|
6
7
|
|
7
8
|
module Unitsdb
|
8
9
|
module Commands
|
9
|
-
class Release <
|
10
|
+
class Release < Base
|
10
11
|
def run
|
11
|
-
#
|
12
|
-
|
13
|
-
|
12
|
+
# Verify all required files exist
|
13
|
+
yaml_files = Unitsdb::Utils::DEFAULT_YAML_FILES.map { |f| File.join(@options[:database], f) }
|
14
|
+
missing_files = yaml_files.reject { |f| File.exist?(f) }
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
16
|
+
if missing_files.any?
|
17
|
+
puts "Error: The following required files are missing:"
|
18
|
+
missing_files.each { |f| puts " - #{f}" }
|
19
|
+
exit(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Extract schema version from any file (they should all have the same version)
|
23
|
+
first_yaml = load_yaml(yaml_files.first)
|
24
|
+
schema_version = first_yaml["schema_version"]
|
25
|
+
|
26
|
+
unless schema_version
|
27
|
+
puts "Error: Could not determine schema version from #{yaml_files.first}"
|
28
|
+
exit(1)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Verify all files have the same schema version
|
32
|
+
inconsistent_files = []
|
33
|
+
yaml_files.each do |file|
|
34
|
+
yaml = load_yaml(file)
|
35
|
+
next unless yaml["schema_version"] != schema_version
|
36
|
+
|
37
|
+
inconsistent_files << {
|
38
|
+
file: file,
|
39
|
+
version: yaml["schema_version"]
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
if inconsistent_files.any?
|
44
|
+
puts "Error: Inconsistent schema versions detected:"
|
45
|
+
puts " Expected version: #{schema_version}"
|
46
|
+
inconsistent_files.each do |info|
|
47
|
+
puts " - #{info[:file]}: #{info[:version]}"
|
48
|
+
end
|
31
49
|
exit(1)
|
32
50
|
end
|
33
51
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
52
|
+
# Create output directory if it doesn't exist
|
53
|
+
output_dir = @options[:output_dir] || "."
|
54
|
+
FileUtils.mkdir_p(output_dir) unless Dir.exist?(output_dir)
|
55
|
+
|
56
|
+
# Generate outputs based on format option
|
57
|
+
format = @options[:format] || "all"
|
58
|
+
|
59
|
+
case format.downcase
|
60
|
+
when "yaml", "all"
|
61
|
+
create_unified_yaml(yaml_files, schema_version, output_dir)
|
62
|
+
end
|
63
|
+
|
64
|
+
case format.downcase
|
65
|
+
when "zip", "all"
|
66
|
+
create_zip_archive(yaml_files, schema_version, output_dir)
|
67
|
+
end
|
68
|
+
|
69
|
+
puts "Release files created successfully in #{output_dir}"
|
38
70
|
end
|
39
71
|
|
40
72
|
private
|
41
73
|
|
42
|
-
def create_unified_yaml(
|
43
|
-
# Create a unified YAML
|
44
|
-
|
45
|
-
|
46
|
-
|
74
|
+
def create_unified_yaml(yaml_files, schema_version, output_dir)
|
75
|
+
# Create a unified YAML structure
|
76
|
+
unified_yaml = { "schema_version" => schema_version }
|
77
|
+
|
78
|
+
# Load each YAML file and add its collection to the unified structure
|
79
|
+
yaml_files.each do |file|
|
80
|
+
yaml = load_yaml(file)
|
81
|
+
# Get the collection key (units, scales, etc.) - it's the key that's not schema_version
|
82
|
+
collection_key = (yaml.keys - ["schema_version"]).first
|
83
|
+
if collection_key
|
84
|
+
# Add the collection to the unified structure
|
85
|
+
unified_yaml[collection_key] = yaml[collection_key]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Write the unified YAML to a file
|
90
|
+
output_file = File.join(output_dir, "unitsdb-#{schema_version}.yaml")
|
91
|
+
File.write(output_file, unified_yaml.to_yaml)
|
92
|
+
puts "Created unified YAML file: #{output_file}"
|
47
93
|
end
|
48
94
|
|
49
|
-
def create_zip_archive(
|
50
|
-
# Create a ZIP archive
|
51
|
-
|
52
|
-
|
53
|
-
Zip::File.open(
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
quantities: Unitsdb::Quantities
|
60
|
-
}.each_pair do |access_method, collection_klass|
|
61
|
-
db.send(access_method).tap do |data|
|
62
|
-
collection = collection_klass.new(access_method => data)
|
63
|
-
collection.version = @options[:version]
|
64
|
-
zipfile.get_output_stream("#{access_method}.yaml") { |f| f.write(collection.to_yaml) }
|
65
|
-
end
|
95
|
+
def create_zip_archive(yaml_files, schema_version, output_dir)
|
96
|
+
# Create a ZIP archive containing all YAML files
|
97
|
+
output_file = File.join(output_dir, "unitsdb-#{schema_version}.zip")
|
98
|
+
|
99
|
+
Zip::File.open(output_file, Zip::File::CREATE) do |zipfile|
|
100
|
+
yaml_files.each do |file|
|
101
|
+
# Get the filename without the path
|
102
|
+
filename = File.basename(file)
|
103
|
+
# Add the file to the ZIP archive
|
104
|
+
zipfile.add(filename, file)
|
66
105
|
end
|
67
106
|
end
|
68
107
|
|
69
|
-
puts "Created ZIP archive: #{
|
108
|
+
puts "Created ZIP archive: #{output_file}"
|
70
109
|
end
|
71
110
|
end
|
72
111
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../base"
|
4
|
-
|
5
3
|
module Unitsdb
|
6
4
|
module Commands
|
7
5
|
module Validate
|
8
|
-
class Identifiers <
|
6
|
+
class Identifiers < Base
|
9
7
|
def run
|
10
8
|
db = load_database
|
11
9
|
all_dups = db.validate_uniqueness
|
@@ -1,11 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../base"
|
4
|
-
|
5
3
|
module Unitsdb
|
6
4
|
module Commands
|
7
5
|
module Validate
|
8
|
-
class References <
|
6
|
+
class References < Base
|
9
7
|
def run
|
10
8
|
# Load the database
|
11
9
|
db = load_database(@options[:database])
|
@@ -103,6 +103,12 @@ module Unitsdb
|
|
103
103
|
puts "Please fix the duplicates by either removing the reference from all but one entity,"
|
104
104
|
puts "or by updating the references to use different URIs appropriate for each entity."
|
105
105
|
end
|
106
|
+
|
107
|
+
def load_database(path)
|
108
|
+
Unitsdb::Database.from_db(path)
|
109
|
+
rescue StandardError => e
|
110
|
+
raise Unitsdb::Errors::DatabaseError, "Failed to load database: #{e.message}"
|
111
|
+
end
|
106
112
|
end
|
107
113
|
end
|
108
114
|
end
|