Boundwit Whiz is a Rails application for creating and maintaining bound-with relationships in Alma.
The application accepts a list of Alma MMS IDs, treats the first bibliographic record as the parent, and updates the related MARC bibliographic and holding records so the titles are represented as a bound-with set.
Given a list of MMS IDs, Boundwit Whiz:
- Treats the first bib as the parent record.
- Retrieves the holdings associated with the parent bib.
- Automatically uses the parent holding when there is only one.
- Prompts the cataloger to select a holding when the parent has multiple holdings.
- Adds
774fields to the parent for each child bib. - Adds a
773field to each child pointing back to the parent. - Adds a
501"Bound with:" note to each bib describing the other titles in the set. - Adds
014fields to the selected parent holding for the related MMS IDs. - Updates the records in Alma.
- Caches the updated MARC records locally so they can be displayed without making another Alma API request.
Alma remains the source of truth.
- Ruby
- Rails
- SQLite for local development
- Access to the Alma API
- Temple SSO configuration when authentication is enabled
Install dependencies:
bundle installPrepare the database:
bin/rails db:prepareThe application uses the alma Ruby gem to communicate with Alma.
Set an Alma API key:
export ALMA_API_KEY=...The API key must have permission to read and update the bibliographic, holding, and user records required by the application.
Production access is restricted to users who:
- Authenticate through Temple SSO.
- Have the
Catalogerrole in Alma.
The application checks the Alma user associated with the SSO identity before granting access.
Development and test environments can disable this access requirement.
For example:
# config/environments/development.rb
config.x.require_cataloger_access =
ENV.fetch("REQUIRE_CATALOGER_ACCESS", "false") == "true"Normal local development:
bin/devTo exercise the real SSO and Alma authorization flow locally:
REQUIRE_CATALOGER_ACCESS=true bin/devProduction should always have cataloger access enforcement enabled.
Start the development environment with:
bin/devbin/dev runs Rails as well as the Dart Sass watcher used to compile the application's Bootstrap styles.
The application uses:
- Rails 8
- RSpec
- Bootstrap
- Dart Sass
- Propshaft
- Importmaps
- Stimulus
- OmniAuth SAML
- ruby-marc
Run the complete test suite:
bundle exec rspecOr run an individual spec:
bundle exec rspec spec/models/marc_record_spec.rbThe test suite should not communicate with Temple SSO or Alma directly. External behavior should be mocked at those boundaries.
OmniAuth test mode is used for SAML request specs.
BoundWith::Preparation prepares a bound-with operation before any MARC records are updated.
It is responsible for:
- Retrieving the supplied bib records from Alma.
- Treating the first bib as the parent.
- Retrieving the holdings associated with the parent bib.
- Raising an error if the parent has no holdings.
- Caching the retrieved bib records locally.
- Determining whether the cataloger needs to select a holding.
- Retrieving and caching the parent holding automatically when only one holding exists.
When the parent has multiple holdings, preparation stops before any Alma updates are made and the controller renders the holding-selection page.
BoundWith::Updater performs the actual bound-with update after the bibs and parent holding have been resolved.
It receives:
BoundWith::Updater.new(
bibs: bibs,
holding: holding
).callIt is responsible for:
- Adding the appropriate
501,773,774, and014fields. - Updating the bib records in Alma.
- Updating the selected parent holding in Alma.
- Caching the successfully updated MARC records locally.
Record retrieval and holding selection belong in BoundWith::Preparation, while MARC-specific manipulation belongs in BoundWith::MarcEditor.
BoundWith::MarcEditor contains the MARC manipulation logic, including creation and removal of:
014501773774
Keeping this logic separate makes it possible to test MARC transformations without making Alma API requests.
The application extends several classes from the alma gem under:
app/lib/alma/
These overrides provide application-specific behavior such as:
- Converting Alma MARCXML into
MARC::Recordinstances. - Updating bib and holding records.
- Retrieving holdings.
- Caching Alma bib and holding records locally.
- Checking whether an Alma user is a cataloger.
- Adapting
Alma::ResultSetto behave correctly with Ruby'sEnumerablemethods.
Overrides are prepended to the appropriate Alma classes from the Alma initializer.
When modifying these overrides, add regression coverage for the actual Alma class as well as the added behavior.
In particular, changes to Alma::ResultSet#each should verify that every record is yielded exactly once. Duplicate iteration can result in duplicate MARC fields being written to Alma.
MarcRecord stores the application's local cached copy of an Alma MARC record.
A record contains:
record_id
record_type
mms_id
title
marc_xml
record_type is currently either:
bib
holding
For a bib:
record_id = MMS ID
mms_id = MMS ID
For a holding:
record_id = holding ID
mms_id = parent bib MMS ID
Only one cached copy of a given Alma record is retained. Alma is authoritative.
Cached MarcRecord objects can also be converted back into Alma bib and holding objects when records need to be carried between steps of the bound-with workflow.
The order of the supplied MMS IDs is significant.
For:
991000000000000001
991000000000000002
991000000000000003
the first record is the parent:
991000000000000001
and the remaining records are children.
The parent must already have the holding/item record that represents the physical bound volume.
Child bibs do not need their own inventory.
The cataloger enters two or more MMS IDs, one per line.
The first MMS ID identifies the parent bib. The remaining MMS IDs identify the child bibs.
The application validates the submitted MMS IDs before beginning the bound-with operation.
BoundWith::Preparation retrieves the bibs from Alma and retrieves the holdings belonging to the parent bib.
If the parent has no holdings, the operation stops with an error.
If the parent has exactly one holding, that holding is automatically selected and the application proceeds directly to the update.
If the parent bib has multiple holdings, the application displays a holding-selection page before making any bound-with changes.
Each available holding is identified by:
- Library
- Location
- Call number
- Holding ID
The cataloger selects the holding representing the physical bound volume and submits the form.
The MMS IDs are carried forward to the second request so the same set of bib records can be used to finish the operation.
Once the holding has been resolved, BoundWith::Updater modifies the MARC records.
For the parent bib:
- Existing generated bound-with fields are removed.
- A
501note describing the bound-with set is added. - A
774field is added for each child bib.
For each child bib:
- Existing generated bound-with fields are removed.
- A
501note describing the bound-with set is added. - A
773field pointing to the parent is added.
For the selected parent holding:
- Existing generated bound-with fields are removed.
- An
014field is added for each child bib.
The changed bibs and selected holding are then written back to Alma.
After Alma has been updated successfully, the changed MARC records are cached locally and the user is redirected to the success page.
The success page displays the bib records and associated holding from the local MarcRecord cache.
The application uses OmniAuth SAML for Temple SSO.
The SAML request phase uses POST binding so authentication requests are accepted by the Temple IdP.
The callback is handled by SessionsController#saml.
After SAML authentication succeeds, the application retrieves the corresponding Alma user and verifies that the user has the Cataloger role before creating the Rails session.
Updated records are shown from the local MarcRecord cache.
The success page provides a view record link for each bib and associated holding.
Records are displayed in a Stimulus-powered modal using standard MARC tags, indicators, and subfields.
The cached MARCXML is parsed back into a MARC::Record when displayed.
Development work may update real Alma records depending on the configured API key.
Before running a bound-with operation:
- Verify which Alma environment the API key targets.
- Prefer dedicated test records.
- Inspect generated MARC changes before testing against production data.
- Do not assume cached records are authoritative.
- Remember that Alma is always the source of truth.
- Confirm that the selected holding represents the intended physical bound volume.
- Be especially careful when modifying collection iteration or MARC field generation, since duplicate processing can produce duplicate fields in Alma.
# Start development
bin/dev
# Rails console
bin/rails console
# Run all tests
bundle exec rspec
# Run one spec
bundle exec rspec spec/services/bound_with/updater_spec.rb
# Prepare database
bin/rails db:prepare
# Run migrations
bin/rails db:migrate
# Show routes
bin/rails routesA bound-with operation now has a preparation phase followed by an update phase:
Browser
|
v
BoundWithsController
|
v
BoundWith::Preparation
|
+--> Alma API
|
+--> MarcRecord cache
|
+--> one holding -------------------------+
| |
+--> multiple holdings |
| |
v |
Holding Selection |
| |
+---------------------------------+
|
v
BoundWith::Updater
|
+-------------+-------------+
| |
v v
BoundWith::MarcEditor Alma API
|
v
MarcRecord cache
Authentication follows a separate path:
Browser
|
v
Temple SSO
|
v
OmniAuth SAML
|
v
SessionsController
|
+--> Alma::User
|
+--> Cataloger role check
Keep controllers thin and put domain behavior in the appropriate service or model.
When changing bound-with behavior:
- Add or update the MARC editor spec.
- Add regression coverage for
BoundWith::Preparationwhen changing record retrieval or holding-selection behavior. - Add regression coverage for
BoundWith::Updaterwhen changing the Alma update workflow. - Verify that records are not processed more than once.
- Test the zero-, one-, and multiple-holding cases when changing holding behavior.
- Test against designated Alma test records before using the change with production data.
When changing an Alma override:
- Test the behavior through the real overridden Alma class.
- Add regression coverage for the specific behavior being fixed.
- Avoid depending on undocumented behavior of the underlying gem where possible.