README.md in active_fedora-noid-2.0.0.beta3 vs README.md in active_fedora-noid-2.0.0.beta4
- old
+ new
@@ -1,12 +1,13 @@
[![Version](https://badge.fury.io/rb/active_fedora-noid.png)](http://badge.fury.io/rb/active_fedora-noid)
+[![Build Status](https://travis-ci.org/projecthydra-labs/active_fedora-noid.png?branch=master)](https://travis-ci.org/projecthydra-labs/active_fedora-noid)
+[![Coverage Status](https://coveralls.io/repos/projecthydra-labs/active_fedora-noid/badge.svg)](https://coveralls.io/r/projecthydra-labs/active_fedora-noid)
+[![Code Climate](https://codeclimate.com/github/projecthydra-labs/active_fedora-noid/badges/gpa.svg)](https://codeclimate.com/github/projecthydra-labs/active_fedora-noid)
+[![Dependency Status](https://gemnasium.com/projecthydra-labs/active_fedora-noid.png)](https://gemnasium.com/projecthydra-labs/active_fedora-noid)
[![Apache 2.0 License](http://img.shields.io/badge/APACHE2-license-blue.svg)](./LICENSE)
[![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md)
[![API Docs](http://img.shields.io/badge/API-docs-blue.svg)](http://rubydoc.info/gems/active_fedora-noid)
-[![Build Status](https://travis-ci.org/projecthydra-labs/active_fedora-noid.png?branch=master)](https://travis-ci.org/projecthydra-labs/active_fedora-noid)
-[![Dependency Status](https://gemnasium.com/projecthydra-labs/active_fedora-noid.png)](https://gemnasium.com/projecthydra-labs/active_fedora-noid)
-[![Coverage Status](https://coveralls.io/repos/projecthydra-labs/active_fedora-noid/badge.svg)](https://coveralls.io/r/projecthydra-labs/active_fedora-noid)
# ActiveFedora::Noid
Override your ActiveFedora-based applications with opaque [Noid](https://wiki.ucop.edu/display/Curation/NOID)-based identifiers.
@@ -94,22 +95,34 @@
This 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`).
## Overriding default behavior
-### Minter state (for replayability)
+The default minter in ActiveFedora::Noid 2.x is the database-backed minter to better support multi-host production installations that expect a shared database but not necessarily a shared filesystem (e.g., between load-balanced Rails applications).
-The default minter creates a Noid and dumps it to a statefile in the /tmp directory. You can override the location or name of this statefile as follows in e.g. `config/initializers/active_fedora-noid.rb`:
+### Use file-based minter state (for replayability)
+The file-based minter -- which was the default and only minter in 1.x -- creates a Noid and dumps it to a statefile in the /tmp directory. You can override the location or name of this statefile as follows in e.g. `config/initializers/active_fedora-noid.rb`:
+
```ruby
require 'active_fedora/noid'
ActiveFedora::Noid.configure do |config|
+ config.minter_class = ActiveFedora::Noid::Minter::File
config.statefile = '/var/foo/bar'
end
```
+**NOTE**: If you switch to a new minter, it will not automatically start with the same state as the old minter. AF::Noid does include a couple of rake tasks for copying state from database-backed minters to file-backed ones and vice versa:
+
+``` bash
+# For migrating minter state from a file to a database
+$ rake active_fedora:noid:migrate:file_to_database
+# For migrating minter state from a database to a file
+$ rake active_fedora:noid:migrate:database_to_file
+```
+
### Identifier template
To 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/active_fedora-noid.rb`:
```ruby
@@ -122,31 +135,41 @@
For 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).
### Custom minters
-If you don't want your minter's state to be persisted, you may also pass in your own minter. First write up a minter class that looks like the following:
+If 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:
```ruby
-class MyMinter
- def initialize(*args)
- # do something if you need initialization
+class MyMinter < ActiveFedora::Noid::Minter::Base
+ def valid?(identifier)
+ # return true/false if you care about ids conforming to templates
end
- def mint
- # spit out an identifier
+ def read
+ # return current minter state
end
- def valid?(identifier)
- # return true/false if you care about ids conforming to templates
+ def write!(state)
+ # write a passed-in minter state
end
+
+ protected
+
+ def next_id
+ # return the next identifier from the minter
+ end
end
```
-Then inject an instance of your minter into ActiveFedora::Noid::Service:
+Then add your new minter class to the ActiveFedora::Noid configuration (`config/initializers/active_fedora-noid.rb`):
```ruby
-noid_service = ActiveFedora::Noid::Service.new(MyMinter.new)
+require 'active_fedora/noid'
+
+ActiveFedora::Noid.configure do |config|
+ config.minter_class = MyMinter
+end
```
And the service will delegate minting and validating to an instance of your customized minter class.
# Help