unitsdb 2.2.2 → 2.2.4

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/opal.yml +36 -0
  3. data/.gitignore +3 -0
  4. data/Gemfile +2 -1
  5. data/Rakefile +3 -1
  6. data/lib/unitsdb/cli.rb +5 -41
  7. data/lib/unitsdb/commands/_modify.rb +1 -34
  8. data/lib/unitsdb/commands/check_si/si_formatter.rb +6 -6
  9. data/lib/unitsdb/commands/check_si/si_matcher.rb +202 -292
  10. data/lib/unitsdb/commands/check_si/si_updater.rb +16 -36
  11. data/lib/unitsdb/commands/entity_presenter.rb +98 -0
  12. data/lib/unitsdb/commands/get.rb +16 -113
  13. data/lib/unitsdb/commands/qudt/formatter.rb +16 -27
  14. data/lib/unitsdb/commands/qudt/matcher.rb +18 -28
  15. data/lib/unitsdb/commands/qudt/updater.rb +8 -11
  16. data/lib/unitsdb/commands/qudt.rb +1 -34
  17. data/lib/unitsdb/commands/search.rb +33 -188
  18. data/lib/unitsdb/commands/thor.rb +41 -0
  19. data/lib/unitsdb/commands/ucum/formatter.rb +9 -18
  20. data/lib/unitsdb/commands/ucum/matcher.rb +4 -4
  21. data/lib/unitsdb/commands/ucum/updater.rb +3 -5
  22. data/lib/unitsdb/commands/ucum.rb +1 -34
  23. data/lib/unitsdb/commands/validate/qudt_references.rb +29 -70
  24. data/lib/unitsdb/commands/validate/references.rb +5 -303
  25. data/lib/unitsdb/commands/validate/si_references.rb +30 -66
  26. data/lib/unitsdb/commands/validate/ucum_references.rb +30 -64
  27. data/lib/unitsdb/commands/validate.rb +1 -36
  28. data/lib/unitsdb/commands.rb +2 -0
  29. data/lib/unitsdb/config.rb +83 -29
  30. data/lib/unitsdb/database/loader.rb +135 -0
  31. data/lib/unitsdb/database/reference_validator.rb +227 -0
  32. data/lib/unitsdb/database/uniqueness_validator.rb +80 -0
  33. data/lib/unitsdb/database.rb +124 -584
  34. data/lib/unitsdb/dimension.rb +0 -27
  35. data/lib/unitsdb/dimensions.rb +0 -2
  36. data/lib/unitsdb/opal.rb +43 -0
  37. data/lib/unitsdb/prefix.rb +0 -13
  38. data/lib/unitsdb/prefixes.rb +0 -2
  39. data/lib/unitsdb/quantities.rb +0 -1
  40. data/lib/unitsdb/quantity.rb +0 -2
  41. data/lib/unitsdb/quantity_reference.rb +0 -2
  42. data/lib/unitsdb/root_unit_reference.rb +0 -2
  43. data/lib/unitsdb/scale.rb +0 -2
  44. data/lib/unitsdb/scale_properties.rb +0 -1
  45. data/lib/unitsdb/scales.rb +0 -1
  46. data/lib/unitsdb/si_derived_base.rb +0 -1
  47. data/lib/unitsdb/symbol_presentations.rb +0 -2
  48. data/lib/unitsdb/unit.rb +0 -34
  49. data/lib/unitsdb/unit_system.rb +0 -2
  50. data/lib/unitsdb/unit_systems.rb +0 -2
  51. data/lib/unitsdb/units.rb +0 -2
  52. data/lib/unitsdb/version.rb +1 -1
  53. data/lib/unitsdb.rb +142 -35
  54. data/unitsdb.gemspec +1 -0
  55. metadata +23 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2982ead6dc990098c687109bd98560cd35945c6272e01a88bcd4f1270ffdffa
4
- data.tar.gz: f89db123f11036b7963fd5fc60a1e37476cd7dac43664be26c95776089479844
3
+ metadata.gz: '098dae7946c10a2e7ed4b5c7f5b3e75e8aed43c0112f9bd49137e629c4c1dfad'
4
+ data.tar.gz: c8fc41cfa9f239b892cf5baf4b8febc48b00db6d433c8421f6b1c24a92ef1dcb
5
5
  SHA512:
6
- metadata.gz: 811a621748d4936a1668e7f6969e5090f4da626b7ca0122bbce24ea1d3b217a533d2ea0e5759a812c22faa4d097941538e9273db4c2f84beb908ee301c0ef51a
7
- data.tar.gz: 23456a3351a981a001f57476bba3815b95c93ce65008189bf1334ae87cf6c0aa57201f897301c8579e0cc9866af10dc2989eb9a58af1aad2c7e63c15d6f05e42
6
+ metadata.gz: e31bda3acc961a0720c039072a6fe13ed94e0790bed425104d455b239569faebd2cb003827ca518c4935e6a89252e0a5b8d4e9d95a37d82a449e7286f62a1bcb
7
+ data.tar.gz: 0d0cc478a993d34134c6fc0f5aa9b62275b8d7de8b66df60dc64895fc94accb273356391086beae96e706a1699117217bf89841c58b8f738918fac59b2208e10
@@ -0,0 +1,36 @@
1
+ name: opal
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ boot-file-spec:
13
+ name: Opal boot file verification
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ with:
18
+ submodules: 'recursive'
19
+
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: '3.3'
24
+ bundler-cache: true
25
+
26
+ - name: Set up Node.js
27
+ uses: actions/setup-node@v4
28
+ with:
29
+ node-version: '18'
30
+
31
+ - name: Run opal boot file spec
32
+ # The spec statically verifies that lib/unitsdb/opal.rb is well-formed
33
+ # (every require resolves to a real file, no Opal-gated entry points
34
+ # leak in, and the boot file actually compiles under Opal::Builder with
35
+ # the native-only deps stubbed).
36
+ run: bundle exec rspec spec/unitsdb/unitsdb_opal_boot_spec.rb
data/.gitignore CHANGED
@@ -11,3 +11,6 @@
11
11
  .rspec_status
12
12
 
13
13
  Gemfile.lock
14
+
15
+ # Local-only refactor audit notes — never commit
16
+ TODO*
data/Gemfile CHANGED
@@ -6,8 +6,9 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  gem "canon"
9
- gem "lutaml-model", github: "lutaml/lutaml-model", branch: "fix/global-context-register-lookup-fallback"
9
+ gem "lutaml-model", github: "lutaml/lutaml-model", branch: "main"
10
10
  gem "nokogiri"
11
+ gem "opal", "~> 1.8"
11
12
  gem "rake"
12
13
  gem "rspec"
13
14
  gem "rubocop"
data/Rakefile CHANGED
@@ -3,7 +3,9 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
5
 
6
- RSpec::Core::RakeTask.new(:spec)
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.pattern = "spec/unitsdb/**/*_spec.rb"
8
+ end
7
9
 
8
10
  require "rubocop/rake_task"
9
11
 
data/lib/unitsdb/cli.rb CHANGED
@@ -1,20 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "thor"
4
- require "fileutils"
5
4
 
6
5
  module Unitsdb
7
- class Cli < Thor
8
- # Enable --trace globally for all subcommands
9
- # When enabled, Thor shows full backtraces on error
10
- class_option :trace, type: :boolean, default: false,
11
- desc: "Show full backtrace on error"
12
-
13
- # Fix Thor deprecation warning
14
- def self.exit_on_failure?
15
- true
16
- end
17
-
6
+ class Cli < Unitsdb::Commands::Thor
18
7
  desc "ucum SUBCOMMAND", "UCUM-related commands"
19
8
  subcommand "ucum", Commands::UcumCommand
20
9
 
@@ -41,7 +30,7 @@ module Unitsdb
41
30
  desc: "Path to UnitsDB database (required)"
42
31
 
43
32
  def search(query)
44
- run_command(Commands::Search, :run, query)
33
+ run_command(Commands::Search, options, query, method: :run)
45
34
  end
46
35
 
47
36
  desc "get ID", "Get detailed information about an entity by ID"
@@ -52,7 +41,7 @@ module Unitsdb
52
41
  option :database, type: :string, required: true, aliases: "-d",
53
42
  desc: "Path to UnitsDB database (required)"
54
43
  def get(id)
55
- run_command(Commands::Get, :get, id)
44
+ run_command(Commands::Get, options, id, method: :get)
56
45
  end
57
46
 
58
47
  desc "check_si",
@@ -71,7 +60,7 @@ module Unitsdb
71
60
  desc: "Path to UnitsDB database (required)"
72
61
 
73
62
  def check_si
74
- run_command(Commands::CheckSiCommand, :run)
63
+ run_command(Commands::CheckSiCommand, options)
75
64
  end
76
65
 
77
66
  desc "release", "Create release files (unified YAML and/or ZIP archive)"
@@ -84,32 +73,7 @@ module Unitsdb
84
73
  option :database, type: :string, required: true, aliases: "-d",
85
74
  desc: "Path to UnitsDB database (required)"
86
75
  def release
87
- run_command(Commands::Release, :run)
88
- end
89
-
90
- private
91
-
92
- def run_command(command_class, method, *args)
93
- command = command_class.new(options)
94
- command.send(method, *args)
95
- rescue Unitsdb::Errors::CLIRuntimeError => e
96
- handle_cli_error(e)
97
- rescue StandardError => e
98
- handle_error(e)
99
- end
100
-
101
- def handle_cli_error(error)
102
- raise error if debugging?
103
-
104
- warn "Error: #{error.message}"
105
- exit 1
106
- end
107
-
108
- def handle_error(error)
109
- raise error if debugging?
110
-
111
- warn "Error: #{error.message}"
112
- exit 1
76
+ run_command(Commands::Release, options)
113
77
  end
114
78
  end
115
79
  end
@@ -4,11 +4,7 @@ require "thor"
4
4
 
5
5
  module Unitsdb
6
6
  module Commands
7
- class ModifyCommand < Thor
8
- # Inherit trace option from parent CLI
9
- class_option :trace, type: :boolean, default: false,
10
- desc: "Show full backtrace on error"
11
-
7
+ class ModifyCommand < Unitsdb::Commands::Thor
12
8
  desc "normalize INPUT OUTPUT",
13
9
  "Normalize a YAML file or all YAML files with --all"
14
10
  method_option :sort, type: :string,
@@ -23,35 +19,6 @@ module Unitsdb
23
19
 
24
20
  def normalize(input = nil, output = nil)
25
21
  run_command(Normalize, options, input, output)
26
- rescue Unitsdb::Errors::CLIRuntimeError => e
27
- handle_cli_error(e)
28
- rescue StandardError => e
29
- handle_error(e)
30
- end
31
-
32
- private
33
-
34
- def run_command(command_class, options, *args)
35
- command = command_class.new(options)
36
- command.run(*args)
37
- end
38
-
39
- def handle_cli_error(error)
40
- if options[:trace]
41
- raise error
42
- else
43
- warn "Error: #{error.message}"
44
- exit 1
45
- end
46
- end
47
-
48
- def handle_error(error)
49
- if options[:trace]
50
- raise error
51
- else
52
- warn "Error: #{error.message}"
53
- exit 1
54
- end
55
22
  end
56
23
  end
57
24
  end
@@ -238,7 +238,7 @@ module Unitsdb
238
238
  matches.each do |match|
239
239
  db_entity = match[:db_entity]
240
240
  entity_id = match[:entity_id] || db_entity.short
241
- entity_name = db_entity.respond_to?(:names) ? db_entity.names&.first : "unnamed"
241
+ entity_name = db_entity.names.first || "unnamed"
242
242
  si_suffix = SiTtlParser.extract_identifying_suffix(match[:ttl_uri])
243
243
 
244
244
  ttl_label = match[:ttl_entity] ? (match[:ttl_entity][:label] || match[:ttl_entity][:name]) : "Unknown"
@@ -279,7 +279,7 @@ module Unitsdb
279
279
  # Get match description if available
280
280
  entity_id = match[:db_entity].short
281
281
  match_pair_key = "#{entity_id}:#{ttl_entities.first[:uri]}"
282
- match_details = Unitsdb::Commands::CheckSi::SiMatcher.instance_variable_get(:@match_details)&.dig(match_pair_key)
282
+ match_details = Unitsdb::Commands::CheckSi::SiMatcher.match_details&.dig(match_pair_key)
283
283
  match_desc = match_details[:match_desc] if match_details && match_details[:match_desc]
284
284
 
285
285
  # Symbol matches and partial matches should always be potential matches
@@ -301,7 +301,7 @@ module Unitsdb
301
301
  exact_matches.each do |match|
302
302
  db_entity = match[:db_entity]
303
303
  entity_id = match[:entity_id] || db_entity.short
304
- entity_name = db_entity.respond_to?(:names) ? db_entity.names&.first : "unnamed"
304
+ entity_name = db_entity.names.first || "unnamed"
305
305
 
306
306
  # Handle multiple TTL entities in a single row
307
307
  ttl_entities = match[:ttl_entities]
@@ -347,7 +347,7 @@ module Unitsdb
347
347
 
348
348
  # Get match details for this match
349
349
  match_pair_key = "#{db_entity.short}:#{ttl_entities.first[:uri]}"
350
- match_details = Unitsdb::Commands::CheckSi::SiMatcher.instance_variable_get(:@match_details)&.dig(match_pair_key)
350
+ match_details = Unitsdb::Commands::CheckSi::SiMatcher.match_details&.dig(match_pair_key)
351
351
 
352
352
  # Format match info
353
353
  match_info = ""
@@ -377,7 +377,7 @@ module Unitsdb
377
377
  potential_matches.each do |match|
378
378
  db_entity = match[:db_entity]
379
379
  entity_id = match[:entity_id] || db_entity.short
380
- entity_name = db_entity.respond_to?(:names) ? db_entity.names&.first : "unnamed"
380
+ entity_name = db_entity.names.first || "unnamed"
381
381
 
382
382
  # Handle multiple TTL entities in a single row
383
383
  ttl_entities = match[:ttl_entities]
@@ -423,7 +423,7 @@ module Unitsdb
423
423
 
424
424
  # Get match details
425
425
  match_pair_key = "#{db_entity.short}:#{ttl_entities.first[:uri]}"
426
- match_details = Unitsdb::Commands::CheckSi::SiMatcher.instance_variable_get(:@match_details)&.dig(match_pair_key)
426
+ match_details = Unitsdb::Commands::CheckSi::SiMatcher.match_details&.dig(match_pair_key)
427
427
 
428
428
  # Format match info
429
429
  match_info = ""