unitsdb 2.1.0 → 2.1.1
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 +92 -15
- data/Gemfile +1 -0
- data/README.adoc +108 -2
- data/lib/unitsdb/cli.rb +7 -0
- data/lib/unitsdb/commands/_modify.rb +2 -2
- data/lib/unitsdb/commands/base.rb +7 -33
- data/lib/unitsdb/commands/normalize.rb +1 -1
- data/lib/unitsdb/commands/release.rb +47 -86
- data/lib/unitsdb/commands/ucum/check.rb +126 -0
- data/lib/unitsdb/commands/ucum/formatter.rb +141 -0
- data/lib/unitsdb/commands/ucum/matcher.rb +301 -0
- data/lib/unitsdb/commands/ucum/update.rb +84 -0
- data/lib/unitsdb/commands/ucum/updater.rb +98 -0
- data/lib/unitsdb/commands/ucum/xml_parser.rb +34 -0
- data/lib/unitsdb/commands/ucum.rb +43 -0
- data/lib/unitsdb/commands/validate/identifiers.rb +3 -1
- data/lib/unitsdb/commands/validate/references.rb +3 -1
- data/lib/unitsdb/commands/validate/si_references.rb +0 -6
- data/lib/unitsdb/commands/validate.rb +3 -3
- data/lib/unitsdb/database.rb +1 -0
- data/lib/unitsdb/dimensions.rb +1 -0
- data/lib/unitsdb/prefixes.rb +1 -0
- data/lib/unitsdb/quantities.rb +1 -0
- data/lib/unitsdb/scales.rb +1 -0
- data/lib/unitsdb/ucum.rb +198 -0
- data/lib/unitsdb/unit_systems.rb +1 -0
- data/lib/unitsdb/units.rb +1 -0
- data/lib/unitsdb/version.rb +1 -1
- data/unitsdb.gemspec +0 -2
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d26a180d24908f27758427140cfc5e01380afc6441ae2f96856523c2dc8f1d9
|
4
|
+
data.tar.gz: 3bc8f78dab0ed305d7f48bdcd07356b3914e87d9a096bdc5fb0cc177c1350d48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8601b692c2c4e0e6191e4e0c3f74a963325c63bd4a0830e20bf7ba1216f514557af8792c137acbd2f233919df6769d90604035f9bd4a8f99f872cb5959921a2e
|
7
|
+
data.tar.gz: 02f631a8c47820816d6415c30d78cb21d16eff2d00dc71ba652fd17a6b7f3e310e874ea1fa21fcb0a0ee71c65d2950dac07a3fde08cc34df8cf4e477550f5b4a
|
data/.rubocop_todo.yml
CHANGED
@@ -1,17 +1,56 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2025-05-
|
3
|
+
# on 2025-05-21 10:17:19 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
|
-
|
10
|
+
# This cop supports safe autocorrection (--autocorrect).
|
11
|
+
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
12
|
+
# SupportedStyles: with_first_element, with_fixed_indentation
|
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:
|
13
52
|
Exclude:
|
14
|
-
- 'unitsdb.
|
53
|
+
- 'lib/unitsdb/commands/ucum/updater.rb'
|
15
54
|
|
16
55
|
# Offense count: 2
|
17
56
|
Lint/ShadowingOuterLocalVariable:
|
@@ -19,12 +58,12 @@ Lint/ShadowingOuterLocalVariable:
|
|
19
58
|
- 'lib/unitsdb/commands/search.rb'
|
20
59
|
- 'lib/unitsdb/commands/validate/si_references.rb'
|
21
60
|
|
22
|
-
# Offense count:
|
61
|
+
# Offense count: 47
|
23
62
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
24
63
|
Metrics/AbcSize:
|
25
64
|
Max: 169
|
26
65
|
|
27
|
-
# Offense count:
|
66
|
+
# Offense count: 31
|
28
67
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
29
68
|
# AllowedMethods: refine
|
30
69
|
Metrics/BlockLength:
|
@@ -33,19 +72,19 @@ Metrics/BlockLength:
|
|
33
72
|
# Offense count: 3
|
34
73
|
# Configuration parameters: CountComments, CountAsOne.
|
35
74
|
Metrics/ClassLength:
|
36
|
-
Max:
|
75
|
+
Max: 442
|
37
76
|
|
38
|
-
# Offense count:
|
77
|
+
# Offense count: 45
|
39
78
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
40
79
|
Metrics/CyclomaticComplexity:
|
41
80
|
Max: 50
|
42
81
|
|
43
|
-
# Offense count:
|
82
|
+
# Offense count: 58
|
44
83
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
45
84
|
Metrics/MethodLength:
|
46
85
|
Max: 169
|
47
86
|
|
48
|
-
# Offense count:
|
87
|
+
# Offense count: 5
|
49
88
|
# Configuration parameters: CountComments, CountAsOne.
|
50
89
|
Metrics/ModuleLength:
|
51
90
|
Max: 369
|
@@ -55,7 +94,7 @@ Metrics/ModuleLength:
|
|
55
94
|
Metrics/ParameterLists:
|
56
95
|
Max: 6
|
57
96
|
|
58
|
-
# Offense count:
|
97
|
+
# Offense count: 39
|
59
98
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
60
99
|
Metrics/PerceivedComplexity:
|
61
100
|
Max: 56
|
@@ -73,17 +112,45 @@ Naming/MethodParameterName:
|
|
73
112
|
- 'lib/unitsdb/commands/si_ttl_parser.rb'
|
74
113
|
- 'lib/unitsdb/utils.rb'
|
75
114
|
|
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
|
+
|
76
126
|
# Offense count: 1
|
77
127
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
78
128
|
Style/CombinableLoops:
|
79
129
|
Exclude:
|
80
130
|
- 'lib/unitsdb/commands/si_matcher.rb'
|
81
131
|
|
82
|
-
# Offense count:
|
132
|
+
# Offense count: 48
|
83
133
|
# Configuration parameters: AllowedConstants.
|
84
134
|
Style/Documentation:
|
85
135
|
Enabled: false
|
86
136
|
|
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
|
+
|
87
154
|
# Offense count: 2
|
88
155
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
89
156
|
Style/IdenticalConditionalBranches:
|
@@ -95,15 +162,25 @@ Style/MultilineBlockChain:
|
|
95
162
|
Exclude:
|
96
163
|
- 'lib/unitsdb/commands/normalize.rb'
|
97
164
|
|
98
|
-
# Offense count:
|
165
|
+
# Offense count: 9
|
99
166
|
# Configuration parameters: AllowedMethods.
|
100
167
|
# AllowedMethods: respond_to_missing?
|
101
168
|
Style/OptionalBooleanParameter:
|
102
169
|
Exclude:
|
103
170
|
- 'lib/unitsdb/commands/check_si.rb'
|
104
171
|
- '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'
|
105
182
|
|
106
|
-
# Offense count:
|
183
|
+
# Offense count: 12
|
107
184
|
# This cop supports safe autocorrection (--autocorrect).
|
108
185
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
109
186
|
# URISchemes: http, https
|
data/Gemfile
CHANGED
data/README.adoc
CHANGED
@@ -101,6 +101,7 @@ 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)
|
104
105
|
dimensions:
|
105
106
|
- identifiers: [...]
|
106
107
|
length: {...}
|
@@ -269,7 +270,7 @@ Options:
|
|
269
270
|
|
270
271
|
`--all`, `-a`:: Process all YAML files in the repository
|
271
272
|
`--database`, `-d`:: Path to UnitsDB database (required)
|
272
|
-
`--sort`:: Sort units by: 'short' (name
|
273
|
+
`--sort`:: Sort units by: 'short' (name), 'nist' (ID, default), 'unitsml' (ID), or 'none'
|
273
274
|
|
274
275
|
|
275
276
|
==== Search
|
@@ -383,6 +384,108 @@ with added SI references
|
|
383
384
|
`--include-potential-matches`, `-p`:: Include potential matches when updating
|
384
385
|
references (default: false)
|
385
386
|
|
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
|
+
|
386
489
|
==== Release
|
387
490
|
|
388
491
|
Creates release files for UnitsDB in unified formats:
|
@@ -400,6 +503,9 @@ $ unitsdb release --format=zip --database=/path/to/unitsdb/data
|
|
400
503
|
|
401
504
|
# Specify output directory
|
402
505
|
$ 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
|
403
509
|
----
|
404
510
|
|
405
511
|
This command creates release files for UnitsDB in two formats:
|
@@ -410,7 +516,7 @@ This command creates release files for UnitsDB in two formats:
|
|
410
516
|
|
411
517
|
The command verifies that all files have the same schema version before creating
|
412
518
|
the release files. The output files are named with the schema version (e.g.,
|
413
|
-
`unitsdb-2.
|
519
|
+
`unitsdb-2.1.0.yaml` and `unitsdb-2.1.0.zip`).
|
414
520
|
|
415
521
|
Options:
|
416
522
|
|
data/lib/unitsdb/cli.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "thor"
|
4
|
+
require_relative "commands/base"
|
4
5
|
require_relative "commands/validate"
|
5
6
|
require_relative "commands/_modify"
|
7
|
+
require_relative "commands/ucum"
|
6
8
|
require "fileutils"
|
7
9
|
|
8
10
|
module Unitsdb
|
@@ -12,6 +14,9 @@ module Unitsdb
|
|
12
14
|
true
|
13
15
|
end
|
14
16
|
|
17
|
+
desc "ucum SUBCOMMAND", "UCUM-related commands"
|
18
|
+
subcommand "ucum", Commands::UcumCommand
|
19
|
+
|
15
20
|
desc "_modify SUBCOMMAND", "Commands that modify the database"
|
16
21
|
subcommand "_modify", Commands::ModifyCommand
|
17
22
|
|
@@ -71,6 +76,8 @@ module Unitsdb
|
|
71
76
|
desc: "Output format: 'yaml' (single file), 'zip' (archive), or 'all' (both)"
|
72
77
|
option :output_dir, type: :string, default: ".", aliases: "-o",
|
73
78
|
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)"
|
74
81
|
option :database, type: :string, required: true, aliases: "-d",
|
75
82
|
desc: "Path to UnitsDB database (required)"
|
76
83
|
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), 'unitsml' (ID), or 'none'"
|
9
|
+
method_option :sort, type: :string, default: "nist",
|
10
|
+
desc: "Sort units by: 'short' (name), 'nist' (ID, default), '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,51 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "thor"
|
4
3
|
require "yaml"
|
5
|
-
|
6
|
-
require_relative "../database"
|
4
|
+
require "fileutils"
|
7
5
|
|
8
6
|
module Unitsdb
|
9
7
|
module Commands
|
10
8
|
class Base
|
11
9
|
def initialize(options = {})
|
12
10
|
@options = options
|
11
|
+
puts "Database directory path: #{@options[:database]}" if @options[:database]
|
13
12
|
end
|
14
13
|
|
15
14
|
protected
|
16
15
|
|
17
|
-
def
|
18
|
-
|
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?
|
16
|
+
def load_database(path = nil)
|
17
|
+
path ||= @options[:database]
|
18
|
+
raise Unitsdb::Errors::DatabaseError, "Database path not specified" unless path
|
34
19
|
|
35
20
|
Unitsdb::Database.from_db(path)
|
36
|
-
rescue
|
37
|
-
|
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")
|
21
|
+
rescue StandardError => e
|
22
|
+
raise Unitsdb::Errors::DatabaseError, "Failed to load database: #{e.message}"
|
49
23
|
end
|
50
24
|
end
|
51
25
|
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 = YAML.safe_load(File.read(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,111 +1,72 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "base"
|
4
3
|
require "yaml"
|
5
4
|
require "zip"
|
6
5
|
require "fileutils"
|
7
6
|
|
8
7
|
module Unitsdb
|
9
8
|
module Commands
|
10
|
-
class Release < Base
|
9
|
+
class Release < ::Unitsdb::Commands::Base
|
11
10
|
def run
|
12
|
-
#
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
49
|
-
exit(1)
|
50
|
-
end
|
11
|
+
# Load the database
|
12
|
+
db = load_database(@options[:database])
|
13
|
+
db.version = @options[:version]
|
51
14
|
|
52
15
|
# Create output directory if it doesn't exist
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
when "
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
16
|
+
FileUtils.mkdir_p(@options[:output_dir])
|
17
|
+
|
18
|
+
# Generate release files based on format option
|
19
|
+
format = (@options[:format] || "all").downcase
|
20
|
+
case format
|
21
|
+
when "yaml"
|
22
|
+
create_unified_yaml(db)
|
23
|
+
when "zip"
|
24
|
+
create_zip_archive(db)
|
25
|
+
when "all"
|
26
|
+
create_unified_yaml(db)
|
27
|
+
create_zip_archive(db)
|
28
|
+
else
|
29
|
+
puts "Invalid format option: #{@options[:format]}"
|
30
|
+
puts "Valid options are: 'yaml', 'zip', or 'all'"
|
31
|
+
exit(1)
|
67
32
|
end
|
68
33
|
|
69
|
-
puts "Release files created successfully in #{output_dir}"
|
34
|
+
puts "Release files created successfully in #{@options[:output_dir]}"
|
35
|
+
rescue Unitsdb::Errors::DatabaseError => e
|
36
|
+
puts "Error: #{e.message}"
|
37
|
+
exit(1)
|
70
38
|
end
|
71
39
|
|
72
40
|
private
|
73
41
|
|
74
|
-
def create_unified_yaml(
|
75
|
-
# Create a unified YAML
|
76
|
-
|
77
|
-
|
78
|
-
|
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}"
|
42
|
+
def create_unified_yaml(db)
|
43
|
+
# Create a unified YAML file with all database components
|
44
|
+
output_path = File.join(@options[:output_dir], "unitsdb-#{@options[:version]}.yaml")
|
45
|
+
File.write(output_path, db.to_yaml)
|
46
|
+
puts "Created unified YAML file: #{output_path}"
|
93
47
|
end
|
94
48
|
|
95
|
-
def create_zip_archive(
|
96
|
-
# Create a ZIP archive
|
97
|
-
|
98
|
-
|
99
|
-
Zip::File.open(
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
49
|
+
def create_zip_archive(db)
|
50
|
+
# Create a ZIP archive with individual YAML files
|
51
|
+
output_path = File.join(@options[:output_dir], "unitsdb-#{@options[:version]}.zip")
|
52
|
+
|
53
|
+
Zip::File.open(output_path, Zip::File::CREATE) do |zipfile|
|
54
|
+
{
|
55
|
+
dimensions: Unitsdb::Dimensions,
|
56
|
+
unit_systems: Unitsdb::UnitSystems,
|
57
|
+
units: Unitsdb::Units,
|
58
|
+
prefixes: Unitsdb::Prefixes,
|
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
|
105
66
|
end
|
106
67
|
end
|
107
68
|
|
108
|
-
puts "Created ZIP archive: #{
|
69
|
+
puts "Created ZIP archive: #{output_path}"
|
109
70
|
end
|
110
71
|
end
|
111
72
|
end
|