noid-rails 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.rspec +2 -0
- data/.rubocop.yml +24 -0
- data/.rubocop_todo.yml +107 -0
- data/.travis.yml +11 -0
- data/CONTRIBUTING.md +159 -0
- data/Gemfile +39 -0
- data/LICENSE +15 -0
- data/README.md +214 -0
- data/Rakefile +23 -0
- data/app/models/minter_state.rb +16 -0
- data/db/migrate/20160610010003_create_minter_states.rb +16 -0
- data/db/migrate/20161021203429_rename_minter_state_random_to_rand.rb +7 -0
- data/lib/generators/noid/rails/install_generator.rb +22 -0
- data/lib/generators/noid/rails/seed_generator.rb +37 -0
- data/lib/noid/rails/config.rb +35 -0
- data/lib/noid/rails/engine.rb +10 -0
- data/lib/noid/rails/minter/base.rb +65 -0
- data/lib/noid/rails/minter/db.rb +82 -0
- data/lib/noid/rails/minter/file.rb +65 -0
- data/lib/noid/rails/minter.rb +5 -0
- data/lib/noid/rails/rspec.rb +67 -0
- data/lib/noid/rails/service.rb +26 -0
- data/lib/noid/rails/version.rb +7 -0
- data/lib/noid-rails.rb +29 -0
- data/lib/tasks/noid_tasks.rake +59 -0
- data/noid-rails.gemspec +31 -0
- data/spec/models/minter_state_spec.rb +41 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/support/minterstate_table.rb +13 -0
- data/spec/support/shared_examples/minter.rb +39 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +16 -0
- data/spec/unit/config_spec.rb +45 -0
- data/spec/unit/db_minter_spec.rb +88 -0
- data/spec/unit/file_minter_spec.rb +54 -0
- data/spec/unit/noid_spec.rb +43 -0
- data/spec/unit/rspec_spec.rb +90 -0
- data/spec/unit/service_spec.rb +32 -0
- metadata +225 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 85e1bde3f1de25e99f93d8d274bab86c7aa9a62abaaf6d4a8b42b31784c5f101
|
4
|
+
data.tar.gz: b18842c43ca3fe1db2b645bc3b763642df52d0c7d81ba3a8624c0862222c6a3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f8404a7e825b8f290cec17553b48d71dba21b443772c284f900e9d7665d7fd36697b4296b8e7b8d091f6208040a5c17a655428ef72e6b0836b619f4c2397d5c
|
7
|
+
data.tar.gz: 9c2229a1871082d14ddc8265a954f649011e2f9594e9ce64d159da1f374cd655cbdbea233b4424f3b49df2d83061a64c477846a84a0d18c8b3e89ecef5f38c8c
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*.rbc
|
2
|
+
capybara-*.html
|
3
|
+
/log
|
4
|
+
/tmp
|
5
|
+
/db/*.sqlite3
|
6
|
+
/public/system
|
7
|
+
/coverage/
|
8
|
+
/spec/tmp
|
9
|
+
**.orig
|
10
|
+
rerun.txt
|
11
|
+
pickle-email-*.html
|
12
|
+
.byebug_history
|
13
|
+
|
14
|
+
# TODO Comment out these rules if you are OK with secrets being uploaded to the repo
|
15
|
+
config/initializers/secret_token.rb
|
16
|
+
config/secrets.yml
|
17
|
+
|
18
|
+
## Environment normalisation:
|
19
|
+
/.bundle
|
20
|
+
/vendor/bundle
|
21
|
+
|
22
|
+
# these should all be checked in to normalise the environment:
|
23
|
+
Gemfile.lock
|
24
|
+
.ruby-gemset
|
25
|
+
.ruby-version
|
26
|
+
pkg
|
27
|
+
|
28
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
29
|
+
.rvmrc
|
30
|
+
|
31
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
32
|
+
/vendor/assets/bower_components
|
33
|
+
*.bowerrc
|
34
|
+
bower.json
|
35
|
+
|
36
|
+
.internal_test_app
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
inherit_from: .rubocop_todo.yml
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.3
|
6
|
+
DisplayCopNames: true
|
7
|
+
|
8
|
+
Bundler/DuplicatedGem:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Rails:
|
12
|
+
Enabled: true
|
13
|
+
|
14
|
+
RSpec/NestedGroups:
|
15
|
+
Max: 4
|
16
|
+
|
17
|
+
Metrics/BlockLength:
|
18
|
+
Exclude:
|
19
|
+
- 'spec/**/*'
|
20
|
+
- 'lib/tasks/**/*.rake'
|
21
|
+
|
22
|
+
Naming/FileName:
|
23
|
+
Exclude:
|
24
|
+
- 'lib/noid-rails.rb'
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
# This configuration was generated by
|
4
|
+
# `rubocop --auto-gen-config`
|
5
|
+
# on 2016-10-25 09:12:51 -0700 using RuboCop version 0.42.0.
|
6
|
+
# The point is for the user to remove these configuration records
|
7
|
+
# one by one as the offenses are removed from the code base.
|
8
|
+
# Note that changes in the inspected code, or installation of new
|
9
|
+
# versions of RuboCop, may require this file to be generated again.
|
10
|
+
|
11
|
+
# Offense count: 47
|
12
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
13
|
+
# URISchemes: http, https
|
14
|
+
Metrics/LineLength:
|
15
|
+
Max: 120
|
16
|
+
|
17
|
+
# Offense count: 2
|
18
|
+
# Configuration parameters: Max.
|
19
|
+
RSpec/ExampleLength:
|
20
|
+
Exclude:
|
21
|
+
- 'spec/unit/db_minter_spec.rb'
|
22
|
+
- 'spec/unit/file_minter_spec.rb'
|
23
|
+
|
24
|
+
RSpec/MessageSpies:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
RSpec/ExpectInHook:
|
28
|
+
Exclude:
|
29
|
+
- 'spec/support/shared_examples/minter.rb'
|
30
|
+
|
31
|
+
# Offense count: 6
|
32
|
+
# Configuration parameters: CustomTransform.
|
33
|
+
RSpec/FilePath:
|
34
|
+
Exclude:
|
35
|
+
- 'spec/unit/config_spec.rb'
|
36
|
+
- 'spec/unit/db_minter_spec.rb'
|
37
|
+
- 'spec/unit/file_minter_spec.rb'
|
38
|
+
- 'spec/unit/noid_spec.rb'
|
39
|
+
- 'spec/unit/service_spec.rb'
|
40
|
+
- 'spec/unit/rspec_spec.rb'
|
41
|
+
|
42
|
+
# Offense count: 9
|
43
|
+
RSpec/LeadingSubject:
|
44
|
+
Exclude:
|
45
|
+
- 'spec/unit/config_spec.rb'
|
46
|
+
- 'spec/unit/file_minter_spec.rb'
|
47
|
+
|
48
|
+
# Offense count: 3
|
49
|
+
RSpec/InstanceVariable:
|
50
|
+
Exclude:
|
51
|
+
- 'spec/unit/rspec_spec.rb'
|
52
|
+
|
53
|
+
# Offense count: 4
|
54
|
+
RSpec/MessageChain:
|
55
|
+
Exclude:
|
56
|
+
- 'spec/unit/config_spec.rb'
|
57
|
+
|
58
|
+
# Offense count: 5
|
59
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
60
|
+
# SupportedStyles: allow, expect
|
61
|
+
RSpec/MessageExpectation:
|
62
|
+
Exclude:
|
63
|
+
- 'spec/support/shared_examples/minter.rb'
|
64
|
+
- 'spec/unit/service_spec.rb'
|
65
|
+
|
66
|
+
# Offense count: 7
|
67
|
+
RSpec/MultipleExpectations:
|
68
|
+
Max: 5
|
69
|
+
|
70
|
+
# Offense count: 36
|
71
|
+
RSpec/NamedSubject:
|
72
|
+
Exclude:
|
73
|
+
- 'spec/support/shared_examples/minter.rb'
|
74
|
+
- 'spec/unit/config_spec.rb'
|
75
|
+
- 'spec/unit/db_minter_spec.rb'
|
76
|
+
- 'spec/unit/file_minter_spec.rb'
|
77
|
+
- 'spec/unit/noid_spec.rb'
|
78
|
+
- 'spec/unit/service_spec.rb'
|
79
|
+
|
80
|
+
# Offense count: 12
|
81
|
+
# Configuration parameters: MaxNesting.
|
82
|
+
RSpec/NestedGroups:
|
83
|
+
Exclude:
|
84
|
+
- 'spec/unit/config_spec.rb'
|
85
|
+
- 'spec/unit/noid_spec.rb'
|
86
|
+
- 'spec/unit/rspec_spec.rb'
|
87
|
+
|
88
|
+
# Offense count: 3
|
89
|
+
# Configuration parameters: IgnoreSymbolicNames.
|
90
|
+
RSpec/VerifiedDoubles:
|
91
|
+
Exclude:
|
92
|
+
- 'spec/unit/config_spec.rb'
|
93
|
+
- 'spec/unit/service_spec.rb'
|
94
|
+
|
95
|
+
# Offense count: 11
|
96
|
+
Style/Documentation:
|
97
|
+
Exclude:
|
98
|
+
- 'spec/**/*'
|
99
|
+
- 'test/**/*'
|
100
|
+
- 'app/models/minter_state.rb'
|
101
|
+
- 'db/migrate/20160610010003_create_minter_states.rb'
|
102
|
+
- 'db/migrate/20161021203429_rename_minter_state_random_to_rand.rb'
|
103
|
+
|
104
|
+
|
105
|
+
Lint/AmbiguousBlockAssociation:
|
106
|
+
Exclude:
|
107
|
+
- 'spec/unit/rspec_spec.rb'
|
data/.travis.yml
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
# How to Contribute
|
2
|
+
|
3
|
+
We want your help to make Project Hydra great.
|
4
|
+
There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
|
5
|
+
|
6
|
+
## Code of Conduct
|
7
|
+
|
8
|
+
The Hydra community is dedicated to providing a welcoming and positive experience for all its
|
9
|
+
members, whether they are at a formal gathering, in a social setting, or taking part in activities
|
10
|
+
online. Please see our [Code of Conduct](https://wiki.duraspace.org/display/hydra/Code+of+Conduct)
|
11
|
+
for more information.
|
12
|
+
|
13
|
+
## Hydra Project Intellectual Property Licensing and Ownership
|
14
|
+
|
15
|
+
All code contributors must have an Individual Contributor License Agreement (iCLA) on file with the Hydra Project Steering Group.
|
16
|
+
If the contributor works for an institution, the institution must have a Corporate Contributor License Agreement (cCLA) on file.
|
17
|
+
|
18
|
+
https://wiki.duraspace.org/display/hydra/Hydra+Project+Intellectual+Property+Licensing+and+Ownership
|
19
|
+
|
20
|
+
You should also add yourself to the `CONTRIBUTORS.md` file in the root of the project.
|
21
|
+
|
22
|
+
## Contribution Tasks
|
23
|
+
|
24
|
+
* Reporting Issues
|
25
|
+
* Making Changes
|
26
|
+
* Documenting Code
|
27
|
+
* Committing Changes
|
28
|
+
* Submitting Changes
|
29
|
+
* Reviewing and Merging Changes
|
30
|
+
|
31
|
+
### Reporting Issues
|
32
|
+
|
33
|
+
* Make sure you have a [GitHub account](https://github.com/signup/free)
|
34
|
+
* Submit a [Github issue](./issues) by:
|
35
|
+
* Clearly describing the issue
|
36
|
+
* Provide a descriptive summary
|
37
|
+
* Explain the expected behavior
|
38
|
+
* Explain the actual behavior
|
39
|
+
* Provide steps to reproduce the actual behavior
|
40
|
+
|
41
|
+
### Making Changes
|
42
|
+
|
43
|
+
* Fork the repository on GitHub
|
44
|
+
* Create a topic branch from where you want to base your work.
|
45
|
+
* This is usually the master branch.
|
46
|
+
* To quickly create a topic branch based on master; `git branch fix/master/my_contribution master`
|
47
|
+
* Then checkout the new branch with `git checkout fix/master/my_contribution`.
|
48
|
+
* Please avoid working directly on the `master` branch.
|
49
|
+
* You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful
|
50
|
+
* Make sure you have added sufficient tests and documentation for your changes.
|
51
|
+
* Test functionality with RSpec; est features / UI with Capybara.
|
52
|
+
* Run _all_ the tests to assure nothing else was accidentally broken.
|
53
|
+
|
54
|
+
### Documenting Code
|
55
|
+
|
56
|
+
* All new public methods, modules, and classes should include inline documentation in [YARD](http://yardoc.org/).
|
57
|
+
* Documentation should seek to answer the question "why does this code exist?"
|
58
|
+
* Document private / protected methods as desired.
|
59
|
+
* If you are working in a file with no prior documentation, do try to document as you gain understanding of the code.
|
60
|
+
* If you don't know exactly what a bit of code does, it is extra likely that it needs to be documented. Take a stab at it and ask for feedback in your pull request. You can use the 'blame' button on GitHub to identify the original developer of the code and @mention them in your comment.
|
61
|
+
* This work greatly increases the usability of the code base and supports the on-ramping of new committers.
|
62
|
+
* We will all be understanding of one another's time constraints in this area.
|
63
|
+
* YARD examples:
|
64
|
+
* [Hydra::Works::RemoveGenericFile](https://github.com/projecthydra-labs/hydra-works/blob/master/lib/hydra/works/services/generic_work/remove_generic_file.rb)
|
65
|
+
* [ActiveTriples::LocalName::Minter](https://github.com/ActiveTriples/active_triples-local_name/blob/master/lib/active_triples/local_name/minter.rb)
|
66
|
+
* [Getting started with YARD](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
|
67
|
+
|
68
|
+
### Committing changes
|
69
|
+
|
70
|
+
* Make commits of logical units.
|
71
|
+
* Your commit should include a high level description of your work in HISTORY.textile
|
72
|
+
* Check for unnecessary whitespace with `git diff --check` before committing.
|
73
|
+
* Make sure your commit messages are [well formed](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
|
74
|
+
* If you created an issue, you can close it by including "Closes #issue" in your commit message. See [Github's blog post for more details](https://github.com/blog/1386-closing-issues-via-commit-messages)
|
75
|
+
|
76
|
+
```
|
77
|
+
Present tense short summary (50 characters or less)
|
78
|
+
|
79
|
+
More detailed description, if necessary. It should be wrapped to 72
|
80
|
+
characters. Try to be as descriptive as you can, even if you think that
|
81
|
+
the commit content is obvious, it may not be obvious to others. You
|
82
|
+
should add such description also if it's already present in bug tracker,
|
83
|
+
it should not be necessary to visit a webpage to check the history.
|
84
|
+
|
85
|
+
Include Closes #<issue-number> when relavent.
|
86
|
+
|
87
|
+
Description can have multiple paragraphs and you can use code examples
|
88
|
+
inside, just indent it with 4 spaces:
|
89
|
+
|
90
|
+
class PostsController
|
91
|
+
def index
|
92
|
+
respond_to do |wants|
|
93
|
+
wants.html { render 'index' }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
You can also add bullet points:
|
99
|
+
|
100
|
+
- you can use dashes or asterisks
|
101
|
+
|
102
|
+
- also, try to indent next line of a point for readability, if it's too
|
103
|
+
long to fit in 72 characters
|
104
|
+
```
|
105
|
+
|
106
|
+
### Submitting Changes
|
107
|
+
|
108
|
+
* Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
|
109
|
+
* Make sure your branch is up to date with its parent branch (i.e. master)
|
110
|
+
* `git checkout master`
|
111
|
+
* `git pull --rebase`
|
112
|
+
* `git checkout <your-branch>`
|
113
|
+
* `git rebase master`
|
114
|
+
* It is a good idea to run your tests again.
|
115
|
+
* If you've made more than one commit take a moment to consider whether squashing commits together would help improve their logical grouping.
|
116
|
+
* [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
|
117
|
+
* `git rebase --interactive master` ([See Github help](https://help.github.com/articles/interactive-rebase))
|
118
|
+
* Squashing your branch's changes into one commit is "good form" and helps the person merging your request to see everything that is going on.
|
119
|
+
* Push your changes to a topic branch in your fork of the repository.
|
120
|
+
* Submit a pull request from your fork to the project.
|
121
|
+
|
122
|
+
### Reviewing and Merging Changes
|
123
|
+
|
124
|
+
We adopted [Github's Pull Request Review](https://help.github.com/articles/about-pull-request-reviews/) for our repositories.
|
125
|
+
Common checks that may occur in our repositories:
|
126
|
+
|
127
|
+
1. Travis CI - where our automated tests are running
|
128
|
+
2. Hound CI - where we check for style violations
|
129
|
+
3. Approval Required - Github enforces at least one person approve a pull request. Also, all reviewers that have chimed in must approve.
|
130
|
+
4. CodeClimate - is our code remaining healthy (at least according to static code analysis)
|
131
|
+
|
132
|
+
If one or more of the required checks failed (or are incomplete), the code should not be merged (and the UI will not allow it). If all of the checks have passed, then anyone on the project (including the pull request submitter) may merge the code.
|
133
|
+
|
134
|
+
*Example: Carolyn submits a pull request, Justin reviews the pull request and approves. However, Justin is still waiting on other checks (Travis CI is usually the culprit), so he does not merge the pull request. Eventually, all of the checks pass. At this point, Carolyn or anyone else may merge the pull request.*
|
135
|
+
|
136
|
+
#### Things to Consider When Reviewing
|
137
|
+
|
138
|
+
First, the person contributing the code is putting themselves out there. Be mindful of what you say in a review.
|
139
|
+
|
140
|
+
* Ask clarifying questions
|
141
|
+
* State your understanding and expectations
|
142
|
+
* Provide example code or alternate solutions, and explain why
|
143
|
+
|
144
|
+
This is your chance for a mentoring moment of another developer. Take time to give an honest and thorough review of what has changed. Things to consider:
|
145
|
+
|
146
|
+
* Does the commit message explain what is going on?
|
147
|
+
* Does the code changes have tests? _Not all changes need new tests, some changes are refactors_
|
148
|
+
* Do new or changed methods, modules, and classes have documentation?
|
149
|
+
* Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
|
150
|
+
* Does the description of the new/changed specs match your understanding of what the spec is doing?
|
151
|
+
|
152
|
+
If you are uncertain, bring other contributors into the conversation by assigning them as a reviewer.
|
153
|
+
|
154
|
+
# Additional Resources
|
155
|
+
|
156
|
+
* [General GitHub documentation](http://help.github.com/)
|
157
|
+
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
|
158
|
+
* [Pro Git](http://git-scm.com/book) is both a free and excellent book about Git.
|
159
|
+
* [A Git Config for Contributing](http://ndlib.github.io/practices/my-typical-per-project-git-config/)
|
data/Gemfile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in noid-rails.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem 'byebug' unless ENV['CI']
|
10
|
+
gem 'coveralls', require: false
|
11
|
+
end
|
12
|
+
|
13
|
+
# BEGIN ENGINE_CART BLOCK
|
14
|
+
# engine_cart: 1.0.1
|
15
|
+
# engine_cart stanza: 0.10.0
|
16
|
+
# the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
|
17
|
+
file = File.expand_path('Gemfile', ENV['ENGINE_CART_DESTINATION'] ||
|
18
|
+
ENV['RAILS_ROOT'] ||
|
19
|
+
File.expand_path('.internal_test_app', File.dirname(__FILE__)))
|
20
|
+
if File.exist?(file)
|
21
|
+
begin
|
22
|
+
eval_gemfile file
|
23
|
+
rescue Bundler::GemfileError => e
|
24
|
+
Bundler.ui.warn '[EngineCart] Skipping Rails application dependencies:'
|
25
|
+
Bundler.ui.warn e.message
|
26
|
+
end
|
27
|
+
else
|
28
|
+
Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in #{file}, using placeholder dependencies"
|
29
|
+
|
30
|
+
if ENV['RAILS_VERSION']
|
31
|
+
if ENV['RAILS_VERSION'] == 'edge'
|
32
|
+
gem 'rails', github: 'rails/rails'
|
33
|
+
ENV['ENGINE_CART_RAILS_OPTIONS'] = '--edge --skip-turbolinks'
|
34
|
+
else
|
35
|
+
gem 'rails', ENV['RAILS_VERSION']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
# END ENGINE_CART BLOCK
|
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
##########################################################################
|
2
|
+
# Copyright 2015 Penn State University
|
3
|
+
# Additional copyright may be held by others, as reflected in the commit log
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
Code: [![Version](https://badge.fury.io/rb/noid-rails.png)](http://badge.fury.io/rb/noid-rails)
|
2
|
+
[![Build Status](https://travis-ci.org/projecthydra/noid-rails.png?branch=master)](https://travis-ci.org/projecthydra/noid-rails)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/github/projecthydra/noid-rails/badge.svg?branch=master)](https://coveralls.io/github/projecthydra/noid-rails?branch=master)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/projecthydra/noid-rails/badges/gpa.svg)](https://codeclimate.com/github/projecthydra/noid-rails)
|
5
|
+
[![Dependency Status](https://gemnasium.com/projecthydra/noid-rails.png)](https://gemnasium.com/projecthydra/noid-rails)
|
6
|
+
|
7
|
+
Docs: [![Documentation Status](https://inch-ci.org/github/projecthydra/noid-rails.svg?branch=master)](https://inch-ci.org/github/projecthydra/noid-rails)
|
8
|
+
[![API Docs](http://img.shields.io/badge/API-docs-blue.svg)](http://rubydoc.info/gems/noid-rails)
|
9
|
+
[![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md)
|
10
|
+
[![Apache 2.0 License](http://img.shields.io/badge/APACHE2-license-blue.svg)](./LICENSE)
|
11
|
+
|
12
|
+
# Noid::Rails
|
13
|
+
|
14
|
+
Override your ActiveFedora-based applications with opaque [Noid](https://wiki.ucop.edu/display/Curation/NOID)-based identifiers.
|
15
|
+
|
16
|
+
**This gem depends only upon ActiveFedora, not on Hydra or HydraHead**
|
17
|
+
|
18
|
+
# Table of Contents
|
19
|
+
|
20
|
+
* [Installation](#installation)
|
21
|
+
* [Usage](#usage)
|
22
|
+
* [Minting and validating identifiers](#minting-and-validating-identifiers)
|
23
|
+
* [ActiveFedora integration](#activefedora-integration)
|
24
|
+
* [Identifier/URI translation](#identifieruri-translation)
|
25
|
+
* [Overriding default behavior](#overriding-default-behavior)
|
26
|
+
* [Use database-based minter state](#use-database-based-minter-state)
|
27
|
+
* [Identifier template](#identifier-template)
|
28
|
+
* [Custom minters](#custom-minters)
|
29
|
+
* [Help](#help)
|
30
|
+
* [Acknowledgments](#acknowledgments)
|
31
|
+
|
32
|
+
# Installation
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
gem 'noid-rails'
|
37
|
+
|
38
|
+
And then execute:
|
39
|
+
|
40
|
+
$ bundle install
|
41
|
+
|
42
|
+
Or install it yourself via:
|
43
|
+
|
44
|
+
$ gem install noid-rails
|
45
|
+
|
46
|
+
# Usage
|
47
|
+
|
48
|
+
## Minting and validating identifiers
|
49
|
+
|
50
|
+
Mint a new Noid:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
noid_service = Noid::Rails::Service.new
|
54
|
+
noid = noid_service.mint
|
55
|
+
```
|
56
|
+
|
57
|
+
This 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:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
noid_service.valid? 'xyz123foobar'
|
61
|
+
> false
|
62
|
+
```
|
63
|
+
|
64
|
+
## ActiveFedora integration
|
65
|
+
|
66
|
+
To get ActiveFedora to automatically call your Noid service whenever a new ActiveFedora object is saved, include the `Noid::Rails::Model`, e.g.:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
# app/models/my_object.rb
|
70
|
+
require 'noid-rails'
|
71
|
+
|
72
|
+
class MyObject < ActiveFedora::Base
|
73
|
+
## This overrides the default behavior, which is to ask Fedora for an id
|
74
|
+
# @see ActiveFedora::Persistence.assign_id
|
75
|
+
def assign_id
|
76
|
+
service.mint
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def service
|
82
|
+
@service ||= Noid::Rails::Service.new
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
### Identifier/URI translation
|
88
|
+
|
89
|
+
As 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`:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
baseparts = 2 + [(Noid::Rails::Config.template.gsub(/\.[rsz]/, '').length.to_f / 2).ceil, 4].min
|
93
|
+
ActiveFedora::Base.translate_uri_to_id = lambda do |uri|
|
94
|
+
uri.to_s.sub(baseurl, '').split('/', baseparts).last
|
95
|
+
end
|
96
|
+
ActiveFedora::Base.translate_id_to_uri = lambda do |id|
|
97
|
+
"#{baseurl}/#{Noid::Rails.treeify(id)}"
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
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`).
|
102
|
+
|
103
|
+
## Overriding default behavior
|
104
|
+
|
105
|
+
The default minter in Noid::Rails is the file-backed minter to preserve default behavior.
|
106
|
+
|
107
|
+
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), we highly recommend swapping in the database-backed minter.
|
108
|
+
|
109
|
+
### Use database-based minter state
|
110
|
+
|
111
|
+
The 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:
|
112
|
+
|
113
|
+
```bash
|
114
|
+
$ rails generate active_fedora:noid:install
|
115
|
+
```
|
116
|
+
|
117
|
+
This will create the necessary database migrations.
|
118
|
+
|
119
|
+
Then run `rake db:migrate`
|
120
|
+
|
121
|
+
To start minting identifiers with the new minter, override the AF::Noid configuration in e.g. `config/initializers/noid-rails.rb`:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
require 'active_fedora/noid'
|
125
|
+
|
126
|
+
Noid::Rails.configure do |config|
|
127
|
+
config.minter_class = Noid::Rails::Minter::Db
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
131
|
+
Using 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`:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
require 'active_fedora/noid/rspec'
|
135
|
+
|
136
|
+
RSpec.configure do |config|
|
137
|
+
include Noid::Rails::RSpec
|
138
|
+
|
139
|
+
config.before(:suite) { disable_production_minter! }
|
140
|
+
config.after(:suite) { enable_production_minter! }
|
141
|
+
end
|
142
|
+
```
|
143
|
+
|
144
|
+
If 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:
|
145
|
+
|
146
|
+
```bash
|
147
|
+
# For migrating minter state from a file to a database
|
148
|
+
$ rake noid:rails:migrate:file_to_database
|
149
|
+
# For migrating minter state from a database to a file
|
150
|
+
$ rake noid:rails:migrate:database_to_file
|
151
|
+
```
|
152
|
+
|
153
|
+
### Identifier template
|
154
|
+
|
155
|
+
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/noid-rails.rb`:
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
require 'noid-rails'
|
159
|
+
|
160
|
+
Noid::Rails.configure do |config|
|
161
|
+
config.template = '.ddddd'
|
162
|
+
end
|
163
|
+
```
|
164
|
+
|
165
|
+
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).
|
166
|
+
|
167
|
+
### Custom minters
|
168
|
+
|
169
|
+
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:
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
class MyMinter < Noid::Rails::Minter::Base
|
173
|
+
def valid?(identifier)
|
174
|
+
# return true/false if you care about ids conforming to templates
|
175
|
+
end
|
176
|
+
|
177
|
+
def read
|
178
|
+
# return current minter state
|
179
|
+
end
|
180
|
+
|
181
|
+
def write!(state)
|
182
|
+
# write a passed-in minter state
|
183
|
+
end
|
184
|
+
|
185
|
+
protected
|
186
|
+
|
187
|
+
def next_id
|
188
|
+
# return the next identifier from the minter
|
189
|
+
end
|
190
|
+
end
|
191
|
+
```
|
192
|
+
|
193
|
+
Then add your new minter class to the Noid::Rails configuration (`config/initializers/noid-rails.rb`):
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
require 'noid-rails'
|
197
|
+
|
198
|
+
Noid::Rails.configure do |config|
|
199
|
+
config.minter_class = MyMinter
|
200
|
+
end
|
201
|
+
```
|
202
|
+
|
203
|
+
And the service will delegate minting and validating to an instance of your customized minter class.
|
204
|
+
|
205
|
+
# Help
|
206
|
+
|
207
|
+
If you have questions or need help, please email [the Hydra community tech list](mailto:hydra-tech@googlegroups.com) or stop by the #dev channel in [the Hydra community Slack team](https://wiki.duraspace.org/pages/viewpage.action?pageId=43910187#Getintouch!-Slack): [![Slack Status](http://slack.projecthydra.org/badge.svg)](http://slack.projecthydra.org/)
|
208
|
+
|
209
|
+
# Acknowledgments
|
210
|
+
|
211
|
+
This software has been developed by and is brought to you by the Hydra community. Learn more at the
|
212
|
+
[Project Hydra website](http://projecthydra.org/).
|
213
|
+
|
214
|
+
![Project Hydra Logo](http://sufia.io/assets/images/hydra_logo.png)
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'engine_cart/rake_task'
|
6
|
+
require 'rubocop/rake_task'
|
7
|
+
|
8
|
+
Dir.glob('lib/tasks/*.rake').each { |r| import r }
|
9
|
+
|
10
|
+
desc 'Run test suite'
|
11
|
+
task :spec do
|
12
|
+
RSpec::Core::RakeTask.new
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run style checker'
|
16
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
17
|
+
task.fail_on_error = true
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Continuous Integration (generate test app and run tests)'
|
21
|
+
task ci: ['rubocop', 'engine_cart:generate', 'spec']
|
22
|
+
|
23
|
+
task default: :ci
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class MinterState < ApplicationRecord
|
4
|
+
validates :namespace, presence: true, uniqueness: true
|
5
|
+
validates :template, presence: true
|
6
|
+
validates :template, format: { with: Object.const_get('Noid::Template::VALID_PATTERN'), message: 'value fails regex' }
|
7
|
+
|
8
|
+
# Creates an initial row for the namespace.
|
9
|
+
# @return [MinterState] the initial minter state
|
10
|
+
def self.seed!(namespace:, template:)
|
11
|
+
create!(
|
12
|
+
namespace: namespace,
|
13
|
+
template: template
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateMinterStates < ActiveRecord::Migration[4.2]
|
4
|
+
def change
|
5
|
+
create_table :minter_states do |t|
|
6
|
+
t.string :namespace, null: false, default: 'default'
|
7
|
+
t.string :template, null: false
|
8
|
+
t.text :counters
|
9
|
+
t.bigint :seq, default: 0
|
10
|
+
t.binary :random
|
11
|
+
t.timestamps null: false
|
12
|
+
end
|
13
|
+
# Use both model and DB-level constraints for consistency while scaling horizontally
|
14
|
+
add_index :minter_states, :namespace, unique: true
|
15
|
+
end
|
16
|
+
end
|