active_fedora-noid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20fa26d109b6ecfbb5ccc9431cb48f02f458da89
4
+ data.tar.gz: 5b94f7fd14d55137a8599008456378a9bd17a6bf
5
+ SHA512:
6
+ metadata.gz: fe1cf757da93d31e07f37faecd8ac3f9a800e426b61b02818f1c32538cfbdeb9e4ce01767b437cccfee806105e1022ed08bcadb7eb3f9b2e166955f100ba3d64
7
+ data.tar.gz: 9f6930197f38afaeaf3bb376c2494be7ea0d2add287b650dc6a0827b2010ecbc885782e8bb2f78de7ee9f3f80b5bbba5756eb1213a82ce9e6cf0453a72f08521
data/.gitignore ADDED
@@ -0,0 +1,31 @@
1
+ *.rbc
2
+ capybara-*.html
3
+ .rspec
4
+ /log
5
+ /tmp
6
+ /db/*.sqlite3
7
+ /public/system
8
+ /coverage/
9
+ /spec/tmp
10
+ **.orig
11
+ rerun.txt
12
+ pickle-email-*.html
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, .ruby-version, .ruby-gemset
24
+
25
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
26
+ .rvmrc
27
+
28
+ # if using bower-rails ignore default bower_components path bower.json files
29
+ /vendor/assets/bower_components
30
+ *.bowerrc
31
+ bower.json
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ afnoid
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1
data/.travis.yml ADDED
@@ -0,0 +1,21 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
4
+ rvm:
5
+ - 2.2
6
+ - 2.1
7
+ env:
8
+ global:
9
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
10
+ notifications:
11
+ email:
12
+ recipients:
13
+ - "ul-dlt-hydra@lists.psu.edu"
14
+ on_success: "change"
15
+ on_failure: "always"
16
+ irc:
17
+ channels:
18
+ - "irc.freenode.org#scholarsphere"
19
+ - "irc.freenode.org#projecthydra"
20
+ template:
21
+ - "%{repository}//%{branch}@%{commit} by %{author}: %{message} - %{build_url}"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_fedora-noid.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,190 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ active_fedora-noid (0.0.1)
5
+ active-fedora
6
+ noid
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ active-fedora (9.0.1)
12
+ active-triples (~> 0.6.0)
13
+ activesupport (>= 4.1.0)
14
+ deprecation
15
+ ldp (~> 0.2.1)
16
+ linkeddata
17
+ nom-xml (>= 0.5.1)
18
+ om (~> 3.1)
19
+ rdf-ldp
20
+ rdf-rdfxml (~> 1.1.0)
21
+ rsolr (~> 1.0.10)
22
+ active-triples (0.6.1)
23
+ activemodel (>= 3.0.0)
24
+ activesupport (>= 3.0.0)
25
+ deprecation (~> 0.1)
26
+ linkeddata (~> 1.1)
27
+ rdf (~> 1.1)
28
+ activemodel (4.2.0)
29
+ activesupport (= 4.2.0)
30
+ builder (~> 3.1)
31
+ activesupport (4.2.0)
32
+ i18n (~> 0.7)
33
+ json (~> 1.7, >= 1.7.7)
34
+ minitest (~> 5.1)
35
+ thread_safe (~> 0.3, >= 0.3.4)
36
+ tzinfo (~> 1.1)
37
+ builder (3.2.2)
38
+ daemons (1.1.9)
39
+ deprecation (0.1.0)
40
+ activesupport
41
+ diff-lcs (1.2.5)
42
+ ebnf (0.3.6)
43
+ haml (~> 4.0)
44
+ rdf (~> 1.1)
45
+ sxp (~> 0.1, >= 0.1.3)
46
+ equivalent-xml (0.5.1)
47
+ nokogiri (>= 1.4.3)
48
+ faraday (0.9.1)
49
+ multipart-post (>= 1.2, < 3)
50
+ haml (4.0.6)
51
+ tilt
52
+ htmlentities (4.3.3)
53
+ http_logger (0.5.1)
54
+ i18n (0.7.0)
55
+ json (1.8.2)
56
+ json-ld (1.1.7)
57
+ rdf (~> 1.1, >= 1.1.4)
58
+ ldp (0.2.2)
59
+ faraday
60
+ http_logger
61
+ linkeddata (>= 1.1)
62
+ slop
63
+ link_header (0.0.8)
64
+ linkeddata (1.1.2)
65
+ equivalent-xml (~> 0.4)
66
+ json-ld (~> 1.1, >= 1.1.7)
67
+ nokogiri (~> 1.6)
68
+ rdf (~> 1.1, >= 1.1.7)
69
+ rdf-aggregate-repo (~> 1.1)
70
+ rdf-isomorphic (~> 1.1)
71
+ rdf-json (~> 1.1)
72
+ rdf-microdata (~> 2.0)
73
+ rdf-n3 (~> 1.1)
74
+ rdf-rdfa (~> 1.1, >= 1.1.5)
75
+ rdf-rdfxml (~> 1.1, >= 1.1.3)
76
+ rdf-reasoner (~> 0.2, >= 0.2.1)
77
+ rdf-trig (~> 1.1, >= 1.1.3)
78
+ rdf-trix (~> 1.1)
79
+ rdf-turtle (~> 1.1, >= 1.1.5)
80
+ sparql (~> 1.1, >= 1.1.4)
81
+ sparql-client (~> 1.1, >= 1.1.3)
82
+ mini_portile (0.6.2)
83
+ minitest (5.5.1)
84
+ multipart-post (2.0.0)
85
+ net-http-persistent (2.9.4)
86
+ noid (0.7.1)
87
+ nokogiri (1.6.6.2)
88
+ mini_portile (~> 0.6.0)
89
+ nom-xml (0.5.2)
90
+ activesupport (>= 3.2.18)
91
+ i18n
92
+ nokogiri
93
+ om (3.1.0)
94
+ activemodel
95
+ activesupport
96
+ nokogiri (>= 1.4.2)
97
+ solrizer (~> 3.3)
98
+ rake (10.4.2)
99
+ rdf (1.1.8)
100
+ link_header (~> 0.0, >= 0.0.8)
101
+ rdf-aggregate-repo (1.1.0)
102
+ rdf (>= 1.1)
103
+ rdf-isomorphic (1.1.0)
104
+ rdf (>= 1.1)
105
+ rdf-json (1.1.1)
106
+ rdf (~> 1.1)
107
+ rdf-ldp (0.0.4)
108
+ rdf
109
+ rdf-microdata (2.0)
110
+ htmlentities (~> 4.3)
111
+ nokogiri (~> 1.6)
112
+ rdf (~> 1.1)
113
+ rdf-xsd (~> 1.1)
114
+ rdf-n3 (1.1.2)
115
+ rdf (~> 1.1, >= 1.1.5)
116
+ rdf-rdfa (1.1.5)
117
+ haml (~> 4.0)
118
+ htmlentities (~> 4.3)
119
+ rdf (~> 1.1, >= 1.1.6)
120
+ rdf-aggregate-repo
121
+ rdf-xsd (~> 1.1)
122
+ rdf-rdfxml (1.1.3)
123
+ htmlentities (~> 4.3)
124
+ rdf (~> 1.1, >= 1.1.6)
125
+ rdf-rdfa (~> 1.1, >= 1.1.4.1)
126
+ rdf-xsd (~> 1.1)
127
+ rdf-reasoner (0.2.1)
128
+ rdf (~> 1.1, >= 1.1.4.2)
129
+ rdf-turtle (~> 1.1)
130
+ rdf-xsd (~> 1.1)
131
+ rdf-trig (1.1.3.1)
132
+ ebnf (~> 0.3, >= 0.3.5)
133
+ rdf (~> 1.1, >= 1.1.2.1)
134
+ rdf-turtle (~> 1.1, >= 1.1.3)
135
+ rdf-trix (1.1.0)
136
+ rdf (>= 1.1)
137
+ rdf-turtle (1.1.5)
138
+ ebnf (~> 0.3, >= 0.3.6)
139
+ rdf (~> 1.1, >= 1.1.4)
140
+ rdf-xsd (1.1.2)
141
+ rdf (~> 1.1)
142
+ rsolr (1.0.10)
143
+ builder (>= 2.1.2)
144
+ rspec (3.2.0)
145
+ rspec-core (~> 3.2.0)
146
+ rspec-expectations (~> 3.2.0)
147
+ rspec-mocks (~> 3.2.0)
148
+ rspec-core (3.2.0)
149
+ rspec-support (~> 3.2.0)
150
+ rspec-expectations (3.2.0)
151
+ diff-lcs (>= 1.2.0, < 2.0)
152
+ rspec-support (~> 3.2.0)
153
+ rspec-mocks (3.2.0)
154
+ diff-lcs (>= 1.2.0, < 2.0)
155
+ rspec-support (~> 3.2.0)
156
+ rspec-support (3.2.1)
157
+ slop (4.0.0)
158
+ solrizer (3.3.0)
159
+ activesupport
160
+ daemons
161
+ nokogiri
162
+ stomp
163
+ xml-simple
164
+ sparql (1.1.4)
165
+ builder (~> 3.0)
166
+ ebnf (~> 0.3, >= 0.3.5)
167
+ rdf (~> 1.1, >= 1.1.4)
168
+ rdf-aggregate-repo (~> 1.1, >= 1.1.0)
169
+ rdf-xsd (~> 1.1)
170
+ sparql-client (~> 1.1)
171
+ sxp (~> 0.1)
172
+ sparql-client (1.1.3.1)
173
+ net-http-persistent (~> 2.9)
174
+ rdf (~> 1.1)
175
+ stomp (1.3.4)
176
+ sxp (0.1.5)
177
+ thread_safe (0.3.4)
178
+ tilt (2.0.1)
179
+ tzinfo (1.2.2)
180
+ thread_safe (~> 0.1)
181
+ xml-simple (1.1.4)
182
+
183
+ PLATFORMS
184
+ ruby
185
+
186
+ DEPENDENCIES
187
+ active_fedora-noid!
188
+ bundler (~> 1.7)
189
+ rake (~> 10.0)
190
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # active_fedora-noid
2
+ Noid identifier services for ActiveFedora-based applications
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ task default: :spec
5
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_fedora/noid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_fedora-noid"
8
+ spec.version = ActiveFedora::Noid::VERSION
9
+ spec.authors = ["Michael J. Giarlo"]
10
+ spec.email = ["leftwing@alumni.rutgers.edu"]
11
+ spec.summary = %q{Noid identifier services for ActiveFedora-based applications}
12
+ spec.description = %q{Noid identifier services for ActiveFedora-based applications.}
13
+ spec.homepage = "https://github.com/psu-stewardship/active_fedora-noid"
14
+ spec.license = "Apache2"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.test_files = spec.files.grep(%r{^spec/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'active-fedora'
21
+ spec.add_dependency 'noid'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency 'rspec'
26
+ end
@@ -0,0 +1,25 @@
1
+ module ActiveFedora
2
+ module Noid
3
+ class Config
4
+ attr_writer :template, :translate_uri_to_id, :translate_id_to_uri, :statefile
5
+
6
+ def template
7
+ @template ||= '.reeddeeddk'
8
+ end
9
+
10
+ def statefile
11
+ @statefile ||= '/tmp/minter-state'
12
+ end
13
+
14
+ def translate_uri_to_id
15
+ lambda { |uri| uri.to_s.split('/')[-1] }
16
+ end
17
+
18
+ def translate_id_to_uri
19
+ lambda do |id|
20
+ "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/#{ActiveFedora::Noid.treeify(id)}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ require 'noid'
2
+
3
+ module ActiveFedora
4
+ module Noid
5
+ class Service
6
+ attr_reader :minter
7
+
8
+ def initialize(minter = default_minter)
9
+ @minter = minter
10
+ end
11
+
12
+ def valid?(identifier)
13
+ minter.valid? identifier
14
+ end
15
+
16
+ def mint
17
+ minter.mint
18
+ end
19
+
20
+ protected
21
+
22
+ def default_minter
23
+ @minter ||= ActiveFedora::Noid::SynchronizedMinter.new
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,54 @@
1
+ require 'noid'
2
+ require 'yaml'
3
+
4
+ module ActiveFedora
5
+ module Noid
6
+ class SynchronizedMinter
7
+ attr_reader :template, :statefile
8
+
9
+ def initialize(template = default_template, statefile = default_statefile)
10
+ @template = template
11
+ @statefile = statefile
12
+ end
13
+
14
+ def mint
15
+ Mutex.new.synchronize do
16
+ while true
17
+ pid = next_id
18
+ return pid unless ActiveFedora::Base.exists?(pid)
19
+ end
20
+ end
21
+ end
22
+
23
+ def valid?(identifier)
24
+ ::Noid::Minter.new(template: template).valid?(identifier)
25
+ end
26
+
27
+ protected
28
+
29
+ def default_template
30
+ @template ||= ActiveFedora::Noid.config.template
31
+ end
32
+
33
+ def default_statefile
34
+ @statefile ||= ActiveFedora::Noid.config.statefile
35
+ end
36
+
37
+ def next_id
38
+ id = ''
39
+ ::File.open(statefile, ::File::RDWR|::File::CREAT, 0644) do |f|
40
+ f.flock(::File::LOCK_EX)
41
+ yaml = ::YAML::load(f.read) || { template: template }
42
+ minter = ::Noid::Minter.new(yaml)
43
+ id = minter.mint
44
+ f.rewind
45
+ yaml = ::YAML::dump(minter.dump)
46
+ f.write yaml
47
+ f.flush
48
+ f.truncate(f.pos)
49
+ end
50
+ id
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveFedora
2
+ module Noid
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ require 'active_fedora/noid/version'
2
+ require 'active_fedora/noid/config'
3
+
4
+ module ActiveFedora
5
+ module Noid
6
+ class << self
7
+ def configure(&block)
8
+ yield config
9
+ end
10
+
11
+ def config
12
+ @config ||= Config.new
13
+ end
14
+
15
+ def treeify(identifier)
16
+ (identifier.scan(/..?/).first(4) + [identifier]).join('/')
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,91 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ =end
91
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'active_fedora/noid/config'
3
+
4
+ describe ActiveFedora::Noid::Config do
5
+ it { is_expected.to respond_to(:template) }
6
+ it { is_expected.to respond_to(:statefile) }
7
+ it { is_expected.to respond_to(:translate_id_to_uri) }
8
+ it { is_expected.to respond_to(:translate_uri_to_id) }
9
+
10
+ describe '#template' do
11
+ let(:default) { '.reeddeeddk' }
12
+
13
+ it 'has a default' do
14
+ expect(subject.template).to eq default
15
+ end
16
+
17
+ describe 'overriding' do
18
+ before { subject.template = custom_template }
19
+
20
+ let(:custom_template) { '.dddddd' }
21
+
22
+ it 'allows setting a custom template' do
23
+ expect(subject.template).to eq custom_template
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'active_fedora/noid'
3
+
4
+ describe ActiveFedora::Noid do
5
+ describe '#configure' do
6
+ it { is_expected.to respond_to(:configure) }
7
+ end
8
+
9
+ describe '#config' do
10
+ it 'returns a config object' do
11
+ expect(subject.config).to be_instance_of ActiveFedora::Noid::Config
12
+ end
13
+ end
14
+
15
+ describe '#treeify' do
16
+ subject { ActiveFedora::Noid.treeify(id) }
17
+ let(:id) { 'abc123def45' }
18
+ it { is_expected.to eq 'ab/c1/23/de/abc123def45' }
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'active_fedora/noid/service'
3
+ require 'active_fedora/noid/synchronized_minter'
4
+
5
+ describe ActiveFedora::Noid::Service do
6
+ describe 'public API' do
7
+ it { is_expected.to respond_to(:valid?) }
8
+ it { is_expected.to respond_to(:mint) }
9
+ end
10
+
11
+ it 'has a default minter' do
12
+ expect(subject.minter).to be_instance_of ActiveFedora::Noid::SynchronizedMinter
13
+ end
14
+
15
+ context 'with a custom minter' do
16
+ let(:minter) { double('minter') }
17
+ let(:identifier) { 'abc123' }
18
+ let(:new_service) { ActiveFedora::Noid::Service.new(minter) }
19
+
20
+ it 'allows injecting a custom minter' do
21
+ expect(new_service.minter).to eq minter
22
+ end
23
+
24
+ it 'delegates validity checking to the minter' do
25
+ expect(minter).to receive(:valid?).with(identifier).once
26
+ new_service.valid? identifier
27
+ end
28
+
29
+ it 'delegates minting to the minter' do
30
+ expect(minter).to receive(:mint).once
31
+ new_service.mint
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'active_fedora'
3
+ require 'active_fedora/noid'
4
+ require 'active_fedora/noid/synchronized_minter'
5
+
6
+ describe ActiveFedora::Noid::SynchronizedMinter do
7
+ it { is_expected.to respond_to(:mint) }
8
+
9
+ it 'has a default template' do
10
+ expect(subject.template).to eq ActiveFedora::Noid.config.template
11
+ end
12
+
13
+ it 'has a default template' do
14
+ expect(subject.template).to eq ActiveFedora::Noid.config.template
15
+ end
16
+
17
+ describe '#initialize' do
18
+ let(:template) { '.rededk' }
19
+ let(:statefile) { '/tmp/foobar' }
20
+
21
+ subject { ActiveFedora::Noid::SynchronizedMinter.new(template, statefile) }
22
+
23
+ it 'respects the custom template' do
24
+ expect(subject.template).to eq template
25
+ end
26
+
27
+ it 'respects the custom statefile' do
28
+ expect(subject.statefile).to eq statefile
29
+ end
30
+ end
31
+
32
+ describe '#mint' do
33
+ before do
34
+ allow(ActiveFedora::Base).to receive(:exists?).and_return(false)
35
+ end
36
+
37
+ subject { ActiveFedora::Noid::Service.new.mint }
38
+
39
+ it { is_expected.not_to be_empty }
40
+
41
+ it 'does not mint the same ID twice in a row' do
42
+ expect(subject).not_to eq ActiveFedora::Noid::Service.new.mint
43
+ end
44
+
45
+ it 'is valid' do
46
+ expect(ActiveFedora::Noid::Service.new.valid?(subject)).to be true
47
+ end
48
+ end
49
+
50
+ context "when the pid already exists in Fedora" do
51
+ let(:existing_pid) { 'ef12ef12f' }
52
+ let(:unique_pid) { 'bb22bb22b' }
53
+
54
+ before do
55
+ allow_any_instance_of(ActiveFedora::Noid::SynchronizedMinter).to receive(:next_id).and_return(existing_pid, unique_pid)
56
+ allow(ActiveFedora::Base).to receive(:exists?).with(existing_pid).and_return(true)
57
+ allow(ActiveFedora::Base).to receive(:exists?).with(unique_pid).and_return(false)
58
+ end
59
+
60
+ it 'skips the existing pid' do
61
+ expect(subject.mint).to eq unique_pid
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_fedora-noid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael J. Giarlo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: active-fedora
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: noid
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Noid identifier services for ActiveFedora-based applications.
84
+ email:
85
+ - leftwing@alumni.rutgers.edu
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".ruby-gemset"
92
+ - ".ruby-version"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - active_fedora-noid.gemspec
100
+ - lib/active_fedora/noid.rb
101
+ - lib/active_fedora/noid/config.rb
102
+ - lib/active_fedora/noid/service.rb
103
+ - lib/active_fedora/noid/synchronized_minter.rb
104
+ - lib/active_fedora/noid/version.rb
105
+ - spec/spec_helper.rb
106
+ - spec/unit/config_spec.rb
107
+ - spec/unit/noid_spec.rb
108
+ - spec/unit/service_spec.rb
109
+ - spec/unit/synchronized_minter_spec.rb
110
+ homepage: https://github.com/psu-stewardship/active_fedora-noid
111
+ licenses:
112
+ - Apache2
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.4.3
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Noid identifier services for ActiveFedora-based applications
134
+ test_files:
135
+ - spec/spec_helper.rb
136
+ - spec/unit/config_spec.rb
137
+ - spec/unit/noid_spec.rb
138
+ - spec/unit/service_spec.rb
139
+ - spec/unit/synchronized_minter_spec.rb