{"id":19341848,"url":"https://github.com/samvera/noid-rails","last_synced_at":"2025-10-13T00:47:21.451Z","repository":{"id":29595197,"uuid":"33135190","full_name":"samvera/noid-rails","owner":"samvera","description":"Noid identifier services for Rails based applications","archived":false,"fork":false,"pushed_at":"2025-06-04T15:34:08.000Z","size":227,"stargazers_count":1,"open_issues_count":2,"forks_count":5,"subscribers_count":67,"default_branch":"main","last_synced_at":"2025-10-06T19:54:54.097Z","etag":null,"topics":["core-components","samvera-community"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"twin10240/practice02-1","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samvera.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-30T16:40:21.000Z","updated_at":"2025-06-04T15:27:41.000Z","dependencies_parsed_at":"2024-09-06T20:08:29.129Z","dependency_job_id":"b8f696ba-0416-48ea-a882-dc6e3dfe6cfb","html_url":"https://github.com/samvera/noid-rails","commit_stats":{"total_commits":137,"total_committers":24,"mean_commits":5.708333333333333,"dds":0.7956204379562044,"last_synced_commit":"f1f5e89ca3def02fa1079affee0eade47988cd3d"},"previous_names":["projecthydra/active_fedora-noid"],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/samvera/noid-rails","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samvera%2Fnoid-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samvera%2Fnoid-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samvera%2Fnoid-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samvera%2Fnoid-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samvera","download_url":"https://codeload.github.com/samvera/noid-rails/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samvera%2Fnoid-rails/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001885,"owners_count":26083197,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["core-components","samvera-community"],"created_at":"2024-11-10T03:32:45.975Z","updated_at":"2025-10-13T00:47:21.419Z","avatar_url":"https://github.com/samvera.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Noid::Rails\n\nCode:\n[![Gem Version](https://badge.fury.io/rb/noid-rails.png)](http://badge.fury.io/rb/noid-rails)\n[![Build Status](https://circleci.com/gh/samvera/noid-rails.svg?style=svg)](https://circleci.com/gh/samvera/noid-rails)\n[![Coverage Status](https://coveralls.io/repos/github/samvera/noid-rails/badge.svg?branch=main)](https://coveralls.io/github/samvera/noid-rails?branch=main)\n[![Maintainability](https://api.codeclimate.com/v1/badges/9c8739a529edc982fdec/maintainability)](https://codeclimate.com/github/samvera/noid-rails/maintainability)\n\nDocs:\n[![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md)\n[![Apache 2.0 License](http://img.shields.io/badge/APACHE2-license-blue.svg)](./LICENSE)\n[![API Docs](http://img.shields.io/badge/API-docs-blue.svg)](http://rubydoc.info/gems/noid-rails)\n[![Documentation Status](https://inch-ci.org/github/samvera/noid-rails.svg?branch=main)](https://inch-ci.org/github/samvera/noid-rails)\n\nCommunity Support: [![Samvera Community Slack](https://img.shields.io/badge/samvera-slack-blueviolet)](http://slack.samvera.org/)\n\n# What is noid-rails?\n\nThis gem mints identifiers for models in your Rails-based application with opaque [Noid](https://wiki.ucop.edu/display/Curation/NOID)-based identifiers.\n\n**This gem depends only upon Rails, not on ActiveFedora**\n\n## Product Owner \u0026 Maintenance\n\n`noid-rails` was a Core Component of the Samvera Community. Given a decline in available labor required for maintenance, this project no longer has a dedicated Product Owner. The documentation for what this means can be found [here](http://samvera.github.io/core_components.html#requirements-for-a-core-component).\n\n### Product Owner\n\n**Vacant**\n\n_Until a Product Owner has been identified, we ask that you please direct all requests for support, bug reports, and general questions to the [`#dev` Channel on the Samvera Slack](https://samvera.slack.com/app_redirect?channel=dev)._\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n\n  - [Minting and validating identifiers](#minting-and-validating-identifiers)\n  - [ActiveFedora integration](#activefedora-integration)\n\n    - [Identifier/URI translation](#identifieruri-translation)\n\n  - [Overriding default behavior](#overriding-default-behavior)\n\n    - [Use database-based minter state](#use-database-based-minter-state)\n    - [Identifier template](#identifier-template)\n    - [Custom minters](#custom-minters)\n\n- [Help](#help)\n\n- [Acknowledgments](#acknowledgments)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```\ngem 'noid-rails'\n```\n\nAnd then execute:\n\n```\n$ bundle install\n```\n\nOr install it yourself via:\n\n```\n$ gem install noid-rails\n```\n\n## Usage\n\n### Minting and validating identifiers\n\nMint a new Noid:\n\n```ruby\nnoid_service = Noid::Rails::Service.new\nnoid = noid_service.mint\n```\n\nThis creates a Noid with the default identifier template, which you can override (see below). Now that you have a service object with a template, you can also use it to validate identifiers to see if they conform to the template:\n\n```ruby\nnoid_service.valid? 'xyz123foobar'\n\u003e false\n```\n\n### ActiveFedora integration\n\nTo get ActiveFedora to automatically call your Noid service whenever a new ActiveFedora object is saved, include the `Noid::Rails::Model`, e.g.:\n\n```ruby\n# app/models/my_object.rb\nrequire 'noid-rails'\n\nclass MyObject \u003c ActiveFedora::Base\n  ## This overrides the default behavior, which is to ask Fedora for an id\n  # @see ActiveFedora::Persistence.assign_id\n  def assign_id\n    service.mint\n  end\n\n  private\n\n  def service\n    @service ||= Noid::Rails::Service.new\n  end\nend\n```\n\n#### Identifier/URI translation\n\nAs Noid::Rails overrides the default identifier minting strategy in ActiveFedora, you will need to let ActiveFedora know how to translate identifiers into URIs and vice versa so that identifiers are laid out in a sustainable way in Fedora. Add the following to e.g. `config/initializers/active_fedora.rb`:\n\n```ruby\nbaseparts = 2 + [(Noid::Rails::Config.template.gsub(/\\.[rsz]/, '').length.to_f / 2).ceil, 4].min\nActiveFedora::Base.translate_uri_to_id = lambda do |uri|\n                                           uri.to_s.sub(baseurl, '').split('/', baseparts).last\n                                         end\nActiveFedora::Base.translate_id_to_uri = lambda do |id|\n                                           \"#{baseurl}/#{Noid::Rails.treeify(id)}\"\n                                         end\n```\n\nThis will make sure your objects have Noid-like identifiers (e.g. `bb22bb22b`) that map to URIs in Fedora (e.g. `bb/22/bb/22/bb22bb22b`).\n\n### Overriding default behavior\n\nThe default minter in Noid::Rails is the file-backed minter to preserve default behavior.\n\nTo better support multi-host production installations that expect a shared database but not necessarily a shared filesystem (e.g., between load-balanced Rails applications), we highly recommend swapping in the database-backed minter.\n\n#### Use database-based minter state\n\nThe database-based minter stores minter state information in your application's relational database. To use it, you'll first need to run the install generator:\n\n```bash\n$ rails generate noid:rails:install\n```\n\nThis will create the necessary database migrations.\n\nThen run `rake db:migrate`\n\nTo start minting identifiers with the new minter, override the AF::Noid configuration in e.g. `config/initializers/noid-rails.rb`:\n\n```ruby\nrequire 'noid-rails'\n\nNoid::Rails.configure do |config|\n  config.minter_class = Noid::Rails::Minter::Db\nend\n```\n\nUsing the database-backed minter can cause problems with your test suite, where it is often sensible to wipe out database rows between tests (which destroys the database-backed minter's state, which renders it unusable). To deal with this and still get the benefits of using the database-backed minter in development and production environments, you'll also want to add the following helper to your `spec/spec_helper.rb`:\n\n```ruby\nrequire 'noid/rails/rspec'\n\nRSpec.configure do |config|\n  include Noid::Rails::RSpec\n\n  config.before(:suite) { disable_production_minter! }\n  config.after(:suite)  { enable_production_minter! }\nend\n```\n\nIf you switch to the new database-backed minter and want to include in that minter the state of your current file-backed minter, Noid::Rails 2.x provides a new rake task that will copy your minter's state from the filesystem to the database:\n\n```bash\n# For migrating minter state from a file to a database\n$ rake noid:rails:migrate:file_to_database\n# For migrating minter state from a database to a file\n$ rake noid:rails:migrate:database_to_file\n```\n\n#### Identifier template\n\nTo override the default identifier pattern -- a nine-character string consisting of two alphanumeric digits, two numeric digits, two alphanumeric digits, two numeric digits, and a check digit -- put the following code in e.g. `config/initializers/noid-rails.rb`:\n\n```ruby\nrequire 'noid-rails'\n\nNoid::Rails.configure do |config|\n  config.template = '.ddddd'\nend\n```\n\nFor more information about the format of Noid patterns, see pages 8-10 of the [Noid documentation](https://wiki.ucop.edu/download/attachments/16744482/noid.pdf).\n\n#### Custom minters\n\nIf you don't want your minter's state to be persisted, you may also write and configure your own minter. First write up a minter class that looks like the following:\n\n```ruby\nclass MyMinter \u003c Noid::Rails::Minter::Base\n  def valid?(identifier)\n    # return true/false if you care about ids conforming to templates\n  end\n\n  def read\n    # return current minter state\n  end\n\n  def write!(state)\n    # write a passed-in minter state\n  end\n\n  protected\n\n  def next_id\n    # return the next identifier from the minter\n  end\nend\n```\n\nThen add your new minter class to the Noid::Rails configuration (`config/initializers/noid-rails.rb`):\n\n```ruby\nrequire 'noid-rails'\n\nNoid::Rails.configure do |config|\n  config.minter_class = MyMinter\nend\n```\n\nAnd the service will delegate minting and validating to an instance of your customized minter class.\n\n## Contributing \n\nIf you're working on PR for this project, create a feature branch off of `main`. \n\nThis repository follows the [Samvera Community Code of Conduct](https://samvera.atlassian.net/wiki/spaces/samvera/pages/405212316/Code+of+Conduct) and [language recommendations](https://github.com/samvera/maintenance/blob/master/templates/CONTRIBUTING.md#language).  Please ***do not*** create a branch called `master` for this repository or as part of your pull request; the branch will either need to be removed or renamed before it can be considered for inclusion in the code base and history of this repository.\n\n## Releasing\n\n1. `bundle install`\n2. Increase the version number in `lib/noid/rails/version.rb`\n3. Increase the same version number in `.github_changelog_generator`\n4. Update `CHANGELOG.md` by running this command:\n\n  ```\n  github_changelog_generator --user samvera --project noid-rails --token YOUR_GITHUB_TOKEN_HERE\n  ```\n\n5. Commit these changes to the main branch\n\n6. Run `rake release`\n\n# Help\n\nThe Samvera community is here to help. Please see our [support guide](./SUPPORT.md).\n\n# Acknowledgments\n\nThis software has been developed by and is brought to you by the Samvera community. Learn more at the [Samvera website](http://samvera.org/).\n\n![Samvera Logo](https://wiki.duraspace.org/download/thumbnails/87459292/samvera-fall-font2-200w.png?version=1\u0026modificationDate=1498550535816\u0026api=v2)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamvera%2Fnoid-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamvera%2Fnoid-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamvera%2Fnoid-rails/lists"}