Add Opal database payload loader#65
Closed
suleman-uzair wants to merge 3 commits into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a dedicated Opal-only hook to inject a bundled UnitsDB payload at runtime, allowing Opal consumers to use Unitsml::Unitsdb::Database.from_db without subclassing or re-implementing loading behavior.
Changes:
- Add
Unitsml::Unitsdb::Database.load_opal_payloadandopal_payloadhelpers to support injected payloads (with fallback to theDATABASEconstant). - Update Opal
from_dbpath to use the newopal_payloadaccessor and raise when missing. - Extend specs to cover the new Opal payload injection behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/unitsml/unitsdb/database.rb | Introduces load_opal_payload/opal_payload and switches Opal loading to use the payload accessor. |
| spec/unitsml/unitsdb/database_spec.rb | Resets Opal payload between examples and adds coverage for the new payload injection hook. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
64ec644 to
85e08a1
Compare
7 tasks
ronaldtse
added a commit
that referenced
this pull request
Jun 27, 2026
Under Opal, autoload declarations do not lazy-execute, so consumers (plurimath-js) need an explicit boot file that eager-requires every autoloaded entry point in dependency order. unitsml is unique among the moxml-dependent gems: it ships a large unitsdb YAML database that must be pre-serialized as a Ruby hash under Opal (no filesystem). This change adds the full Opal toolchain for unitsml: - lib/unitsml/opal.rb: boot file eager-requiring every autoloaded entry point. Requires upstream boot files (unitsdb/opal, mml/opal, omml/opal) and the payload file so Database.from_db can satisfy without a filesystem. - lib/unitsml/opal/payload_generator.rb: Unitsml::Opal::PayloadGenerator class that reads unitsdb-ruby YAML data on MRI and emits a Ruby source file defining Unitsml::Unitsdb::Database::DATABASE as a frozen hash. Invoked via rake unitsml:generate_opal_payload. - lib/unitsml/opal/database_payload.rb: AUTO-GENERATED output committed to the gem. Loaded by the boot file under Opal. - lib/unitsml/unitsdb/database.rb: adopts the loader mechanism from fix/opal-database-payload-loader (load_opal_payload, opal_payload, reset_opal_payload) so tests can inject small payloads and the committed DATABASE constant is found via const_defined?(:DATABASE, false). Supersedes PR #65. - lib/unitsml/unitsdb.rb, lib/unitsml/model.rb and the four nested model parent files: convert require_relative and __dir__-interpolated autoloads to plain load-path-relative autoload declarations, per the global rule. Removes a dangling autoload (Unitsml::Model:: Namespace) whose target file never existed; MRI never tripped on it because nothing referenced the constant, but Opal eager-loads every autoload and would have crashed. - Rakefile: adds the unitsml:generate_opal_payload task. - Gemfile: adds nokogiri and opal so the boot-file spec can compile the boot file end-to-end via Opal::Builder with native deps stubbed. - .rubocop.yml: excludes the generated payload file from lint. - spec/unitsml/opal_boot_spec.rb: verifies the boot file structure and that Opal::Builder compiles it end-to-end with stubs. - spec/unitsml/payload_sync_spec.rb: verifies the committed payload matches what the generator produces from the current unitsdb gem and that it round-trips through from_hash. - spec/unitsml/opal/payload_generator_spec.rb: verifies the generator produces evaluable Ruby that reproduces the source database. - spec/unitsml/unitsdb/database_spec.rb: extends coverage to the new loader mechanism (load_opal_payload, DATABASE fallback). - .github/workflows/opal.yml: GHA workflow running the opal specs on Ubuntu/Ruby 3.3/Node 18.
ronaldtse
added a commit
that referenced
this pull request
Jun 27, 2026
Under Opal, autoload declarations do not lazy-execute, so consumers (plurimath-js) need an explicit boot file that eager-requires every autoloaded entry point in dependency order. unitsml is unique among the moxml-dependent gems: it ships a large unitsdb YAML database that must be pre-serialized as a Ruby hash under Opal (no filesystem). This change adds the full Opal toolchain for unitsml: - lib/unitsml/opal.rb: boot file eager-requiring every autoloaded entry point. Requires upstream boot files (unitsdb/opal, mml/opal, omml/opal) and the payload file so Database.from_db can satisfy without a filesystem. - lib/unitsml/opal/payload_generator.rb: Unitsml::Opal::PayloadGenerator class that reads unitsdb-ruby YAML data on MRI and emits a Ruby source file defining Unitsml::Unitsdb::Database::DATABASE as a frozen hash. Invoked via rake unitsml:generate_opal_payload. - lib/unitsml/opal/database_payload.rb: AUTO-GENERATED output committed to the gem. Loaded by the boot file under Opal. - lib/unitsml/unitsdb/database.rb: adopts the loader mechanism from fix/opal-database-payload-loader (load_opal_payload, opal_payload, reset_opal_payload) so tests can inject small payloads and the committed DATABASE constant is found via const_defined?(:DATABASE, false). Supersedes PR #65. - lib/unitsml/unitsdb.rb, lib/unitsml/model.rb and the four nested model parent files: convert require_relative and __dir__-interpolated autoloads to plain load-path-relative autoload declarations, per the global rule. Removes a dangling autoload (Unitsml::Model:: Namespace) whose target file never existed; MRI never tripped on it because nothing referenced the constant, but Opal eager-loads every autoload and would have crashed. - Rakefile: adds the unitsml:generate_opal_payload task. - Gemfile: adds nokogiri and opal so the boot-file spec can compile the boot file end-to-end via Opal::Builder with native deps stubbed. - .rubocop.yml: excludes the generated payload file from lint. - spec/unitsml/opal_boot_spec.rb: verifies the boot file structure and that Opal::Builder compiles it end-to-end with stubs. - spec/unitsml/payload_sync_spec.rb: verifies the committed payload matches what the generator produces from the current unitsdb gem and that it round-trips through from_hash. - spec/unitsml/opal/payload_generator_spec.rb: verifies the generator produces evaluable Ruby that reproduces the source database. - spec/unitsml/unitsdb/database_spec.rb: extends coverage to the new loader mechanism (load_opal_payload, DATABASE fallback). - .github/workflows/opal.yml: GHA workflow running the opal specs on Ubuntu/Ruby 3.3/Node 18.
5 tasks
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an explicit
Unitsml::Unitsdb::Database.load_opal_payloadhook for Opal builds.This lets downstream packages provide the bundled UnitsDB payload without generating subclasses or reimplementing
from_db. The Opal loader remains owned byunitsml-ruby, including the missing-payload error path.