active_fedora-noid 2.0.0.beta5 → 2.0.0.beta6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/.rubocop_todo.yml +96 -0
- data/Gemfile +2 -1
- data/README.md +17 -9
- data/Rakefile +16 -6
- data/active_fedora-noid.gemspec +13 -10
- data/app/models/minter_state.rb +1 -0
- data/db/migrate/20160610010003_create_minter_states.rb +1 -0
- data/db/migrate/20161021203429_rename_minter_state_random_to_rand.rb +1 -0
- data/lib/active_fedora/noid.rb +3 -1
- data/lib/active_fedora/noid/config.rb +2 -1
- data/lib/active_fedora/noid/engine.rb +1 -0
- data/lib/active_fedora/noid/minter.rb +1 -0
- data/lib/active_fedora/noid/minter/base.rb +5 -4
- data/lib/active_fedora/noid/minter/db.rb +3 -3
- data/lib/active_fedora/noid/minter/file.rb +2 -1
- data/lib/active_fedora/noid/rspec.rb +1 -0
- data/lib/active_fedora/noid/service.rb +3 -6
- data/lib/active_fedora/noid/version.rb +2 -1
- data/lib/generators/active_fedora/noid/install_generator.rb +1 -0
- data/lib/generators/active_fedora/noid/seed_generator.rb +3 -2
- data/lib/tasks/noid_tasks.rake +5 -4
- data/spec/models/minter_state_spec.rb +10 -9
- data/spec/spec_helper.rb +3 -2
- data/spec/support/minterstate_table.rb +1 -0
- data/spec/support/shared_examples/minter.rb +2 -1
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +2 -1
- data/spec/unit/config_spec.rb +20 -19
- data/spec/unit/db_minter_spec.rb +10 -9
- data/spec/unit/file_minter_spec.rb +7 -7
- data/spec/unit/noid_spec.rb +14 -1
- data/spec/unit/service_spec.rb +2 -1
- metadata +32 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e04703fc928d905a2fdabb0bdf8c967e1b4fef9f
|
|
4
|
+
data.tar.gz: 0d40c8fb02c9542e9437650dc4fa412f9e123682
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6263908c04be9f4e91ae44e21451b3bfd6a32cde46d5e6b612887cd278df4e5b5e15f1852a6bd04e226430eadaca546e18749b536141d223f8f9f0f8e3679d8
|
|
7
|
+
data.tar.gz: cbf2b293055b1505e4f8c45038ae1764b1cef69c2423cdbbfcfdded6608b854bed38a2ee8a3f1a14545e911de33e3558baff788d6c8cdf67f74448de2c9089b3
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
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: 176
|
|
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
|
+
# Offense count: 5
|
|
25
|
+
# Configuration parameters: CustomTransform.
|
|
26
|
+
RSpec/FilePath:
|
|
27
|
+
Exclude:
|
|
28
|
+
- 'spec/unit/config_spec.rb'
|
|
29
|
+
- 'spec/unit/db_minter_spec.rb'
|
|
30
|
+
- 'spec/unit/file_minter_spec.rb'
|
|
31
|
+
- 'spec/unit/noid_spec.rb'
|
|
32
|
+
- 'spec/unit/service_spec.rb'
|
|
33
|
+
|
|
34
|
+
# Offense count: 9
|
|
35
|
+
RSpec/LeadingSubject:
|
|
36
|
+
Exclude:
|
|
37
|
+
- 'spec/unit/config_spec.rb'
|
|
38
|
+
- 'spec/unit/file_minter_spec.rb'
|
|
39
|
+
|
|
40
|
+
# Offense count: 4
|
|
41
|
+
RSpec/MessageChain:
|
|
42
|
+
Exclude:
|
|
43
|
+
- 'spec/unit/config_spec.rb'
|
|
44
|
+
|
|
45
|
+
# Offense count: 5
|
|
46
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
47
|
+
# SupportedStyles: allow, expect
|
|
48
|
+
RSpec/MessageExpectation:
|
|
49
|
+
Exclude:
|
|
50
|
+
- 'spec/support/shared_examples/minter.rb'
|
|
51
|
+
- 'spec/unit/service_spec.rb'
|
|
52
|
+
|
|
53
|
+
# Offense count: 7
|
|
54
|
+
RSpec/MultipleExpectations:
|
|
55
|
+
Max: 5
|
|
56
|
+
|
|
57
|
+
# Offense count: 36
|
|
58
|
+
RSpec/NamedSubject:
|
|
59
|
+
Exclude:
|
|
60
|
+
- 'spec/support/shared_examples/minter.rb'
|
|
61
|
+
- 'spec/unit/config_spec.rb'
|
|
62
|
+
- 'spec/unit/db_minter_spec.rb'
|
|
63
|
+
- 'spec/unit/file_minter_spec.rb'
|
|
64
|
+
- 'spec/unit/noid_spec.rb'
|
|
65
|
+
- 'spec/unit/service_spec.rb'
|
|
66
|
+
|
|
67
|
+
# Offense count: 11
|
|
68
|
+
# Configuration parameters: MaxNesting.
|
|
69
|
+
RSpec/NestedGroups:
|
|
70
|
+
Exclude:
|
|
71
|
+
- 'spec/unit/config_spec.rb'
|
|
72
|
+
- 'spec/unit/noid_spec.rb'
|
|
73
|
+
|
|
74
|
+
# Offense count: 3
|
|
75
|
+
# Configuration parameters: IgnoreSymbolicNames.
|
|
76
|
+
RSpec/VerifiedDoubles:
|
|
77
|
+
Exclude:
|
|
78
|
+
- 'spec/unit/config_spec.rb'
|
|
79
|
+
- 'spec/unit/service_spec.rb'
|
|
80
|
+
|
|
81
|
+
# Offense count: 11
|
|
82
|
+
Style/Documentation:
|
|
83
|
+
Exclude:
|
|
84
|
+
- 'spec/**/*'
|
|
85
|
+
- 'test/**/*'
|
|
86
|
+
- 'app/models/minter_state.rb'
|
|
87
|
+
- 'db/migrate/20160610010003_create_minter_states.rb'
|
|
88
|
+
- 'db/migrate/20161021203429_rename_minter_state_random_to_rand.rb'
|
|
89
|
+
- 'lib/active_fedora/noid.rb'
|
|
90
|
+
- 'lib/active_fedora/noid/config.rb'
|
|
91
|
+
- 'lib/active_fedora/noid/minter/base.rb'
|
|
92
|
+
- 'lib/active_fedora/noid/minter/db.rb'
|
|
93
|
+
- 'lib/active_fedora/noid/minter/file.rb'
|
|
94
|
+
- 'lib/active_fedora/noid/service.rb'
|
|
95
|
+
- 'lib/generators/active_fedora/noid/install_generator.rb'
|
|
96
|
+
- 'lib/generators/active_fedora/noid/seed_generator.rb'
|
data/Gemfile
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
source 'https://rubygems.org'
|
|
2
3
|
|
|
3
4
|
# Specify your gem's dependencies in active_fedora-noid.gemspec
|
|
@@ -36,7 +37,7 @@ else
|
|
|
36
37
|
when /^4.2/
|
|
37
38
|
gem 'responders', '~> 2.0'
|
|
38
39
|
gem 'sass-rails', '>= 5.0'
|
|
39
|
-
gem 'coffee-rails', '~> 4.
|
|
40
|
+
gem 'coffee-rails', '~> 4.2.0'
|
|
40
41
|
when /^4.[01]/
|
|
41
42
|
gem 'sass-rails', '< 5.0'
|
|
42
43
|
end
|
data/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
[](http://badge.fury.io/rb/active_fedora-noid)
|
|
1
|
+
Code: [](http://badge.fury.io/rb/active_fedora-noid)
|
|
2
2
|
[](https://travis-ci.org/projecthydra-labs/active_fedora-noid)
|
|
3
|
-
[](https://coveralls.io/
|
|
3
|
+
[](https://coveralls.io/github/projecthydra-labs/active_fedora-noid?branch=master)
|
|
4
4
|
[](https://codeclimate.com/github/projecthydra-labs/active_fedora-noid)
|
|
5
5
|
[](https://gemnasium.com/projecthydra-labs/active_fedora-noid)
|
|
6
|
-
|
|
7
|
-
[](https://inch-ci.org/github/projecthydra-labs/active_fedora-noid)
|
|
8
8
|
[](http://rubydoc.info/gems/active_fedora-noid)
|
|
9
|
+
[](./CONTRIBUTING.md)
|
|
10
|
+
[](./LICENSE)
|
|
9
11
|
|
|
10
12
|
# ActiveFedora::Noid
|
|
11
13
|
|
|
@@ -21,7 +23,7 @@ Override your ActiveFedora-based applications with opaque [Noid](https://wiki.uc
|
|
|
21
23
|
* [ActiveFedora integration](#activefedora-integration)
|
|
22
24
|
* [Identifier/URI translation](#identifieruri-translation)
|
|
23
25
|
* [Overriding default behavior](#overriding-default-behavior)
|
|
24
|
-
* [
|
|
26
|
+
* [Use database-based minter state](#use-database-based-minter-state)
|
|
25
27
|
* [Identifier template](#identifier-template)
|
|
26
28
|
* [Custom minters](#custom-minters)
|
|
27
29
|
* [Help](#help)
|
|
@@ -103,7 +105,13 @@ To better support multi-host production installations that expect a shared datab
|
|
|
103
105
|
|
|
104
106
|
### Use database-based minter state
|
|
105
107
|
|
|
106
|
-
The database-based minter stores minter state information in your application's relational database. To use it,
|
|
108
|
+
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:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
$ rails generate active_fedora:noid:install
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
This will create the necessary database tables and seed the database minter. To start minting identifiers with the new minter, override the AF::Noid configuration in e.g. `config/initializers/active_fedora-noid.rb`:
|
|
107
115
|
|
|
108
116
|
```ruby
|
|
109
117
|
require 'active_fedora/noid'
|
|
@@ -182,11 +190,11 @@ And the service will delegate minting and validating to an instance of your cust
|
|
|
182
190
|
|
|
183
191
|
# Help
|
|
184
192
|
|
|
185
|
-
If you have questions or need help, please email [the Hydra community tech list](mailto:hydra-tech@googlegroups.com) or stop by [the Hydra community
|
|
193
|
+
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): [](http://slack.projecthydra.org/)
|
|
186
194
|
|
|
187
195
|
# Acknowledgments
|
|
188
196
|
|
|
189
197
|
This software has been developed by and is brought to you by the Hydra community. Learn more at the
|
|
190
|
-
[Project Hydra website](http://projecthydra.org)
|
|
198
|
+
[Project Hydra website](http://projecthydra.org/).
|
|
191
199
|
|
|
192
|
-

|
data/Rakefile
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'bundler/gem_tasks'
|
|
2
3
|
require 'rspec/core/rake_task'
|
|
3
4
|
require 'engine_cart/rake_task'
|
|
4
|
-
|
|
5
|
-
task default: :ci
|
|
6
|
-
RSpec::Core::RakeTask.new
|
|
5
|
+
require 'rubocop/rake_task'
|
|
7
6
|
|
|
8
7
|
Dir.glob('lib/tasks/*.rake').each { |r| import r }
|
|
9
8
|
|
|
10
|
-
desc '
|
|
11
|
-
task
|
|
9
|
+
desc 'Run test suite'
|
|
10
|
+
task :spec do
|
|
11
|
+
RSpec::Core::RakeTask.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
desc 'Run style checker'
|
|
15
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
|
16
|
+
task.fail_on_error = true
|
|
12
17
|
end
|
|
18
|
+
|
|
19
|
+
desc 'Continuous Integration (generate test app and run tests)'
|
|
20
|
+
task ci: ['rubocop', 'engine_cart:generate', 'spec']
|
|
21
|
+
|
|
22
|
+
task default: :ci
|
data/active_fedora-noid.gemspec
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
5
|
require 'active_fedora/noid/version'
|
|
5
6
|
|
|
6
7
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name =
|
|
8
|
+
spec.name = 'active_fedora-noid'
|
|
8
9
|
spec.version = ActiveFedora::Noid::VERSION
|
|
9
|
-
spec.authors = [
|
|
10
|
-
spec.email = [
|
|
11
|
-
spec.summary =
|
|
12
|
-
spec.description =
|
|
13
|
-
spec.homepage =
|
|
14
|
-
spec.license =
|
|
10
|
+
spec.authors = ['Michael J. Giarlo']
|
|
11
|
+
spec.email = ['leftwing@alumni.rutgers.edu']
|
|
12
|
+
spec.summary = 'Noid identifier services for ActiveFedora-based applications'
|
|
13
|
+
spec.description = 'Noid identifier services for ActiveFedora-based applications.'
|
|
14
|
+
spec.homepage = 'https://github.com/projecthydra-labs/active_fedora-noid'
|
|
15
|
+
spec.license = 'Apache2'
|
|
15
16
|
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
|
17
18
|
spec.test_files = spec.files.grep(%r{^spec/})
|
|
18
|
-
spec.require_paths = [
|
|
19
|
+
spec.require_paths = ['lib']
|
|
19
20
|
|
|
20
21
|
spec.add_dependency 'active-fedora', '>= 9.7', '< 12'
|
|
21
22
|
spec.add_dependency 'noid', '~> 0.9'
|
|
22
23
|
spec.add_dependency 'rails', '>= 4.2.7.1', '< 6'
|
|
23
24
|
|
|
24
|
-
spec.add_development_dependency
|
|
25
|
-
spec.add_development_dependency
|
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
|
26
|
+
spec.add_development_dependency 'rake', '~> 11.0'
|
|
26
27
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
|
27
28
|
spec.add_development_dependency 'sqlite3'
|
|
29
|
+
spec.add_development_dependency 'rubocop', '~> 0.42.0'
|
|
30
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.5'
|
|
28
31
|
spec.add_development_dependency 'engine_cart', '~> 1.0'
|
|
29
32
|
end
|
data/app/models/minter_state.rb
CHANGED
data/lib/active_fedora/noid.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'active_fedora/noid/version'
|
|
2
3
|
require 'active_fedora/noid/config'
|
|
3
4
|
require 'active_fedora/noid/engine'
|
|
@@ -7,7 +8,7 @@ require 'active_fedora/noid/minter'
|
|
|
7
8
|
module ActiveFedora
|
|
8
9
|
module Noid
|
|
9
10
|
class << self
|
|
10
|
-
def configure
|
|
11
|
+
def configure
|
|
11
12
|
yield config
|
|
12
13
|
end
|
|
13
14
|
|
|
@@ -16,6 +17,7 @@ module ActiveFedora
|
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def treeify(identifier)
|
|
20
|
+
raise ArgumentError, 'Identifier must be a string of size > 0 in order to be treeified' if identifier.blank?
|
|
19
21
|
head = identifier.split('/').first
|
|
20
22
|
head.gsub!(/#.*/, '')
|
|
21
23
|
(head.scan(/..?/).first(4) + [identifier]).join('/')
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module ActiveFedora
|
|
2
3
|
module Noid
|
|
3
4
|
class Config
|
|
@@ -39,7 +40,7 @@ module ActiveFedora
|
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
def baseparts
|
|
42
|
-
2 + [(template.gsub(/\.[rsz]/,'').length.to_f/2).ceil, 4].min
|
|
43
|
+
2 + [(template.gsub(/\.[rsz]/, '').length.to_f / 2).ceil, 4].min
|
|
43
44
|
end
|
|
44
45
|
end
|
|
45
46
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'noid'
|
|
2
3
|
require 'active_fedora'
|
|
3
4
|
|
|
@@ -20,7 +21,7 @@ module ActiveFedora
|
|
|
20
21
|
# @return [String] the minted identifier
|
|
21
22
|
def mint
|
|
22
23
|
Mutex.new.synchronize do
|
|
23
|
-
|
|
24
|
+
loop do
|
|
24
25
|
pid = next_id
|
|
25
26
|
return pid unless ActiveFedora::Base.exists?(pid) || ActiveFedora::Base.gone?(pid)
|
|
26
27
|
end
|
|
@@ -30,7 +31,7 @@ module ActiveFedora
|
|
|
30
31
|
##
|
|
31
32
|
# @return [Hash] an object representing the current minter state
|
|
32
33
|
def read
|
|
33
|
-
raise NotImplementedError
|
|
34
|
+
raise NotImplementedError, 'Implement #read in child class'
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
##
|
|
@@ -40,7 +41,7 @@ module ActiveFedora
|
|
|
40
41
|
#
|
|
41
42
|
# @return [void]
|
|
42
43
|
def write!(_)
|
|
43
|
-
raise NotImplementedError
|
|
44
|
+
raise NotImplementedError, 'Implement #write! in child class'
|
|
44
45
|
end
|
|
45
46
|
|
|
46
47
|
protected
|
|
@@ -54,7 +55,7 @@ module ActiveFedora
|
|
|
54
55
|
##
|
|
55
56
|
# @return [String] a new identifier.
|
|
56
57
|
def next_id
|
|
57
|
-
raise NotImplementedError
|
|
58
|
+
raise NotImplementedError, 'Implement #next_id in child class'
|
|
58
59
|
end
|
|
59
60
|
end
|
|
60
61
|
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'noid'
|
|
2
3
|
|
|
3
4
|
module ActiveFedora
|
|
4
5
|
module Noid
|
|
5
6
|
module Minter
|
|
6
7
|
class Db < Base
|
|
7
|
-
|
|
8
8
|
def read
|
|
9
|
-
filtered_hash = instance.as_json.select { |key|
|
|
9
|
+
filtered_hash = instance.as_json.select { |key| %w(template counters seq rand namespace).include?(key) }
|
|
10
10
|
filtered_hash['counters'] = JSON.parse(filtered_hash['counters'], symbolize_names: true) if filtered_hash['counters']
|
|
11
11
|
filtered_hash.symbolize_keys
|
|
12
12
|
end
|
|
@@ -46,7 +46,7 @@ module ActiveFedora
|
|
|
46
46
|
def instance
|
|
47
47
|
MinterState.lock.find_by(
|
|
48
48
|
namespace: ActiveFedora::Noid.config.namespace,
|
|
49
|
-
template: ActiveFedora::Noid.config.template
|
|
49
|
+
template: ActiveFedora::Noid.config.template
|
|
50
50
|
)
|
|
51
51
|
end
|
|
52
52
|
end # class Db
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'noid'
|
|
2
3
|
|
|
3
4
|
module ActiveFedora
|
|
@@ -32,7 +33,7 @@ module ActiveFedora
|
|
|
32
33
|
protected
|
|
33
34
|
|
|
34
35
|
def with_file
|
|
35
|
-
::File.open(statefile, 'a+b',
|
|
36
|
+
::File.open(statefile, 'a+b', 0o644) do |f|
|
|
36
37
|
f.flock(::File::LOCK_EX)
|
|
37
38
|
# Files opened in append mode seek to end of file
|
|
38
39
|
f.rewind
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'noid'
|
|
2
3
|
|
|
3
4
|
module ActiveFedora
|
|
@@ -9,13 +10,9 @@ module ActiveFedora
|
|
|
9
10
|
@minter = minter
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
minter.valid? identifier
|
|
14
|
-
end
|
|
13
|
+
delegate :valid?, to: :minter
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
minter.mint
|
|
18
|
-
end
|
|
15
|
+
delegate :mint, to: :minter
|
|
19
16
|
|
|
20
17
|
protected
|
|
21
18
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module ActiveFedora
|
|
2
3
|
module Noid
|
|
3
4
|
class SeedGenerator < Rails::Generators::Base
|
|
4
5
|
source_root ::File.expand_path('../templates', __FILE__)
|
|
5
|
-
argument :namespace, :
|
|
6
|
-
argument :template, :
|
|
6
|
+
argument :namespace, type: :string, default: ActiveFedora::Noid.config.namespace
|
|
7
|
+
argument :template, type: :string, default: ActiveFedora::Noid.config.template
|
|
7
8
|
|
|
8
9
|
desc <<-END_OF_DESC
|
|
9
10
|
Seeds DB from ActiveFedora::Noid.config (or command-line overrides)
|
data/lib/tasks/noid_tasks.rake
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'active_fedora/noid'
|
|
2
3
|
require 'noid'
|
|
3
4
|
require 'yaml'
|
|
@@ -10,7 +11,7 @@ namespace :active_fedora do
|
|
|
10
11
|
statefile = ENV.fetch('AFNOID_STATEFILE', ActiveFedora::Noid.config.statefile)
|
|
11
12
|
raise "File not found: #{statefile}\nAborting" unless File.exist?(statefile)
|
|
12
13
|
puts "Migrating #{statefile} from YAML to Marshal serialization..."
|
|
13
|
-
File.open(statefile, 'a+b',
|
|
14
|
+
File.open(statefile, 'a+b', 0o644) do |f|
|
|
14
15
|
f.flock(File::LOCK_EX)
|
|
15
16
|
f.rewind
|
|
16
17
|
begin
|
|
@@ -23,7 +24,7 @@ namespace :active_fedora do
|
|
|
23
24
|
new_state = Marshal.dump(minter.dump)
|
|
24
25
|
f.write(new_state)
|
|
25
26
|
end
|
|
26
|
-
puts
|
|
27
|
+
puts 'Done!'
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
desc 'Migrate minter state from file to database'
|
|
@@ -35,7 +36,7 @@ namespace :active_fedora do
|
|
|
35
36
|
minter = Noid::Minter.new(state)
|
|
36
37
|
new_state = ActiveFedora::Noid::Minter::Db.new
|
|
37
38
|
new_state.write!(minter)
|
|
38
|
-
puts
|
|
39
|
+
puts 'Done!'
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
desc 'Migrate minter state from database to file'
|
|
@@ -47,7 +48,7 @@ namespace :active_fedora do
|
|
|
47
48
|
minter = Noid::Minter.new(state)
|
|
48
49
|
new_state = ActiveFedora::Noid::Minter::File.new
|
|
49
50
|
new_state.write!(minter)
|
|
50
|
-
puts
|
|
51
|
+
puts 'Done!'
|
|
51
52
|
end
|
|
52
53
|
end
|
|
53
54
|
end
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
include MinterStateHelper
|
|
2
3
|
|
|
3
4
|
describe MinterState, type: :model do
|
|
4
|
-
before
|
|
5
|
-
after(
|
|
5
|
+
before { reset_minter_state_table }
|
|
6
|
+
after(:all) { reset_minter_state_table }
|
|
6
7
|
|
|
7
8
|
let(:state) { described_class.new }
|
|
8
9
|
let(:first) { described_class.first }
|
|
9
10
|
|
|
10
11
|
it 'db is seeded with first row' do
|
|
11
|
-
expect{ first }.not_to raise_error
|
|
12
|
+
expect { first }.not_to raise_error
|
|
12
13
|
expect(first.namespace).to eq 'default'
|
|
13
14
|
expect(first.template).to eq '.reeddeeddk'
|
|
14
15
|
expect(first.seq).to eq 0
|
|
@@ -16,24 +17,24 @@ describe MinterState, type: :model do
|
|
|
16
17
|
end
|
|
17
18
|
describe 'validation' do
|
|
18
19
|
it 'blocks invalid template' do
|
|
19
|
-
expect{ state.save! }.to raise_error(ActiveRecord::RecordInvalid) # empty
|
|
20
|
+
expect { state.save! }.to raise_error(ActiveRecord::RecordInvalid) # empty
|
|
20
21
|
state.template = 'bad_template'
|
|
21
|
-
expect{ state.save! }.to raise_error(ActiveRecord::RecordInvalid)
|
|
22
|
+
expect { state.save! }.to raise_error(ActiveRecord::RecordInvalid)
|
|
22
23
|
state.template = 'reeddddk' # close, but missing '.'
|
|
23
|
-
expect{ state.save! }.to raise_error(ActiveRecord::RecordInvalid)
|
|
24
|
+
expect { state.save! }.to raise_error(ActiveRecord::RecordInvalid)
|
|
24
25
|
end
|
|
25
26
|
it 'allows valid template (edit)' do
|
|
26
27
|
first.template = '.reeddddk'
|
|
27
|
-
expect{ first.save! }.not_to raise_error # OK!
|
|
28
|
+
expect { first.save! }.not_to raise_error # OK!
|
|
28
29
|
end
|
|
29
30
|
it 'blocks new record in same namespace' do
|
|
30
31
|
state.template = '.reeddddk'
|
|
31
|
-
expect{ state.save! }.to raise_error(ActiveRecord::RecordInvalid)
|
|
32
|
+
expect { state.save! }.to raise_error(ActiveRecord::RecordInvalid)
|
|
32
33
|
end
|
|
33
34
|
it 'allows new record in distinct namespace' do
|
|
34
35
|
state.template = '.reeddddk'
|
|
35
36
|
state.namespace = 'foobar'
|
|
36
|
-
expect{ state.save! }.not_to raise_error # OK!
|
|
37
|
+
expect { state.save! }.not_to raise_error # OK!
|
|
37
38
|
expect(described_class.group(:namespace).count).to eq('default' => 1, 'foobar' => 1)
|
|
38
39
|
end
|
|
39
40
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
ENV['RAILS_ENV'] ||= 'test'
|
|
2
3
|
|
|
3
4
|
require 'coveralls'
|
|
4
5
|
Coveralls.wear!
|
|
@@ -9,7 +10,7 @@ require 'active_fedora'
|
|
|
9
10
|
require 'active_fedora/noid'
|
|
10
11
|
require 'byebug' unless ENV['CI']
|
|
11
12
|
|
|
12
|
-
Dir[File.dirname(__FILE__) +
|
|
13
|
+
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
|
|
13
14
|
|
|
14
15
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
15
16
|
RSpec.configure do |config|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
shared_examples 'a minter' do
|
|
2
3
|
describe '#mint' do
|
|
3
4
|
subject { minter.mint }
|
|
@@ -27,7 +28,7 @@ shared_examples 'a minter' do
|
|
|
27
28
|
let(:existing_pid) { 'ef12ef12f' }
|
|
28
29
|
let(:unique_pid) { 'bb22bb22b' }
|
|
29
30
|
|
|
30
|
-
before
|
|
31
|
+
before do
|
|
31
32
|
expect(subject).to receive(:next_id).and_return(existing_pid, unique_pid)
|
|
32
33
|
end
|
|
33
34
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'rails/generators'
|
|
2
3
|
|
|
3
4
|
class TestAppGenerator < Rails::Generators::Base
|
|
4
|
-
source_root
|
|
5
|
+
source_root './spec/test_app_templates'
|
|
5
6
|
|
|
6
7
|
# if you need to generate any additional configuration
|
|
7
8
|
# into the test app, this generator will be run immediately
|
data/spec/unit/config_spec.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
describe ActiveFedora::Noid::Config do
|
|
2
3
|
subject { described_class.new }
|
|
3
4
|
|
|
@@ -45,23 +46,23 @@ describe ActiveFedora::Noid::Config do
|
|
|
45
46
|
describe '#translate_uri_to_id' do
|
|
46
47
|
let(:config) { described_class.new }
|
|
47
48
|
let(:translator) { config.translate_uri_to_id }
|
|
48
|
-
let(:uri) {
|
|
49
|
+
let(:uri) { 'http://localhost:8983/fedora/rest/test/hh/63/vz/22/hh63vz22q/members' }
|
|
49
50
|
let(:ActiveFedora) { double(ActiveFedora) }
|
|
50
51
|
subject { translator.call(uri) }
|
|
51
52
|
before do
|
|
52
|
-
allow(ActiveFedora).to receive_message_chain(
|
|
53
|
-
allow(ActiveFedora).to receive_message_chain(
|
|
53
|
+
allow(ActiveFedora).to receive_message_chain('fedora.host') { 'http://localhost:8983' }
|
|
54
|
+
allow(ActiveFedora).to receive_message_chain('fedora.base_path') { '/fedora/rest/test' }
|
|
54
55
|
end
|
|
55
56
|
|
|
56
57
|
it { is_expected.to eq 'hh63vz22q/members' }
|
|
57
58
|
|
|
58
|
-
context
|
|
59
|
-
let(:uri) {
|
|
59
|
+
context 'with a hash code uri' do
|
|
60
|
+
let(:uri) { 'http://localhost:8983/fedora/rest/test/hh/63/vz/22/hh63vz22q#g123' }
|
|
60
61
|
it { is_expected.to eq 'hh63vz22q#g123' }
|
|
61
62
|
end
|
|
62
63
|
|
|
63
64
|
context 'with a short custom template' do
|
|
64
|
-
let(:uri) {
|
|
65
|
+
let(:uri) { 'http://localhost:8983/fedora/rest/test/ab/cd/abcd/members' }
|
|
65
66
|
let(:custom_template) { '.reeee' }
|
|
66
67
|
before { config.template = custom_template }
|
|
67
68
|
subject { translator.call(uri) }
|
|
@@ -70,7 +71,7 @@ describe ActiveFedora::Noid::Config do
|
|
|
70
71
|
end
|
|
71
72
|
|
|
72
73
|
context 'with an even shorter custom template' do
|
|
73
|
-
let(:uri) {
|
|
74
|
+
let(:uri) { 'http://localhost:8983/fedora/rest/test/ab/c/abc/members' }
|
|
74
75
|
let(:custom_template) { '.reee' }
|
|
75
76
|
before { config.template = custom_template }
|
|
76
77
|
subject { translator.call(uri) }
|
|
@@ -79,7 +80,7 @@ describe ActiveFedora::Noid::Config do
|
|
|
79
80
|
end
|
|
80
81
|
|
|
81
82
|
context 'with a long custom template' do
|
|
82
|
-
let(:uri) {
|
|
83
|
+
let(:uri) { 'http://localhost:8983/fedora/rest/test/ab/cd/ef/gh/abcdefghijklmnopqrstuvwxyz/members' }
|
|
83
84
|
let(:custom_template) { '.reeeeeeeeeeeeeeeeeeeeeeeeee' }
|
|
84
85
|
before { config.template = custom_template }
|
|
85
86
|
subject { translator.call(uri) }
|
|
@@ -91,27 +92,27 @@ describe ActiveFedora::Noid::Config do
|
|
|
91
92
|
describe '#translate_id_to_uri' do
|
|
92
93
|
let(:config) { described_class.new }
|
|
93
94
|
let(:translator) { config.translate_id_to_uri }
|
|
94
|
-
let(:id) {
|
|
95
|
+
let(:id) { 'hh63vz2/members' }
|
|
95
96
|
let(:ActiveFedora) { double(ActiveFedora) }
|
|
96
97
|
subject { translator.call(id) }
|
|
97
98
|
before do
|
|
98
|
-
allow(ActiveFedora).to receive_message_chain(
|
|
99
|
-
allow(ActiveFedora).to receive_message_chain(
|
|
99
|
+
allow(ActiveFedora).to receive_message_chain('fedora.host') { 'http://localhost:8983' }
|
|
100
|
+
allow(ActiveFedora).to receive_message_chain('fedora.base_path') { '/fedora/rest/test' }
|
|
100
101
|
end
|
|
101
102
|
|
|
102
|
-
it { is_expected.to eq
|
|
103
|
+
it { is_expected.to eq 'http://localhost:8983/fedora/rest/test/hh/63/vz/2/hh63vz2/members' }
|
|
103
104
|
|
|
104
|
-
context
|
|
105
|
+
context 'with a hash code id' do
|
|
105
106
|
let(:id) { 'hh63vz2#g123' }
|
|
106
|
-
it { is_expected.to eq
|
|
107
|
+
it { is_expected.to eq 'http://localhost:8983/fedora/rest/test/hh/63/vz/2/hh63vz2#g123' }
|
|
107
108
|
end
|
|
108
109
|
|
|
109
110
|
context 'with a short custom template' do
|
|
110
|
-
let(:id) {
|
|
111
|
+
let(:id) { 'abcd/members' }
|
|
111
112
|
let(:custom_template) { '.reeee' }
|
|
112
113
|
before { config.template = custom_template }
|
|
113
114
|
subject { translator.call(id) }
|
|
114
|
-
it { is_expected.to eq
|
|
115
|
+
it { is_expected.to eq 'http://localhost:8983/fedora/rest/test/ab/cd/abcd/members' }
|
|
115
116
|
end
|
|
116
117
|
|
|
117
118
|
context 'with an even shorter custom template' do
|
|
@@ -119,15 +120,15 @@ describe ActiveFedora::Noid::Config do
|
|
|
119
120
|
let(:custom_template) { '.reee' }
|
|
120
121
|
before { config.template = custom_template }
|
|
121
122
|
subject { translator.call(id) }
|
|
122
|
-
it { is_expected.to eq
|
|
123
|
+
it { is_expected.to eq 'http://localhost:8983/fedora/rest/test/ab/c/abc/members' }
|
|
123
124
|
end
|
|
124
125
|
|
|
125
126
|
context 'with a long custom template' do
|
|
126
|
-
let(:id) {
|
|
127
|
+
let(:id) { 'abcdefghijklmnopqrstuvwxyz/members' }
|
|
127
128
|
let(:custom_template) { '.reeeeeeeeeeeeeeeeeeeeeeeeee' }
|
|
128
129
|
before { config.template = custom_template }
|
|
129
130
|
subject { translator.call(id) }
|
|
130
|
-
it { is_expected.to eq
|
|
131
|
+
it { is_expected.to eq 'http://localhost:8983/fedora/rest/test/ab/cd/ef/gh/abcdefghijklmnopqrstuvwxyz/members' }
|
|
131
132
|
end
|
|
132
133
|
end
|
|
133
134
|
end
|
data/spec/unit/db_minter_spec.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
include MinterStateHelper
|
|
2
3
|
|
|
3
4
|
describe ActiveFedora::Noid::Minter::Db do
|
|
4
|
-
before
|
|
5
|
+
before { reset_minter_state_table }
|
|
5
6
|
after(:all) { reset_minter_state_table }
|
|
6
7
|
|
|
7
|
-
before
|
|
8
|
+
before do
|
|
8
9
|
# default novel mintings
|
|
9
10
|
allow(ActiveFedora::Base).to receive(:exists?).and_return(false)
|
|
10
11
|
allow(ActiveFedora::Base).to receive(:gone?).and_return(false)
|
|
@@ -18,8 +19,8 @@ describe ActiveFedora::Noid::Minter::Db do
|
|
|
18
19
|
|
|
19
20
|
describe '#initialize' do
|
|
20
21
|
it 'raises on bad templates' do
|
|
21
|
-
expect{ described_class.new('reeddeeddk') }.to raise_error(Noid::TemplateError)
|
|
22
|
-
expect{ described_class.new('') }.to raise_error(Noid::TemplateError)
|
|
22
|
+
expect { described_class.new('reeddeeddk') }.to raise_error(Noid::TemplateError)
|
|
23
|
+
expect { described_class.new('') }.to raise_error(Noid::TemplateError)
|
|
23
24
|
end
|
|
24
25
|
it 'returns object w/ default template' do
|
|
25
26
|
expect(subject).to be_instance_of described_class
|
|
@@ -53,11 +54,11 @@ describe ActiveFedora::Noid::Minter::Db do
|
|
|
53
54
|
before { minter.mint }
|
|
54
55
|
it 'changes the state of the minter' do
|
|
55
56
|
expect { subject.write!(minter) }.to change { subject.read[:seq] }
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
.from(starting_state[:seq]).to(minter.seq)
|
|
58
|
+
.and change { subject.read[:counters] }
|
|
59
|
+
.from(starting_state[:counters]).to(minter.counters)
|
|
60
|
+
.and change { subject.read[:rand] }
|
|
61
|
+
.from(starting_state[:rand]).to(Marshal.dump(minter.instance_variable_get(:@rand)))
|
|
61
62
|
end
|
|
62
63
|
end
|
|
63
64
|
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
describe ActiveFedora::Noid::Minter::File do
|
|
2
|
-
before
|
|
3
|
+
before do
|
|
3
4
|
# default novel mintings
|
|
4
5
|
allow(ActiveFedora::Base).to receive(:exists?).and_return(false)
|
|
5
6
|
allow(ActiveFedora::Base).to receive(:gone?).and_return(false)
|
|
@@ -47,12 +48,11 @@ describe ActiveFedora::Noid::Minter::File do
|
|
|
47
48
|
before { minter.mint }
|
|
48
49
|
it 'changes the state of the minter' do
|
|
49
50
|
expect { subject.write!(minter) }.to change { subject.read[:seq] }
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
.from(starting_state[:seq]).to(minter.seq)
|
|
52
|
+
.and change { subject.read[:rand] }
|
|
53
|
+
.from(starting_state[:rand]).to(Marshal.dump(minter.instance_variable_get(:@rand)))
|
|
54
|
+
.and change { subject.read[:counters] }
|
|
55
|
+
.to(minter.counters)
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
end
|
data/spec/unit/noid_spec.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
describe ActiveFedora::Noid do
|
|
2
3
|
describe '#configure' do
|
|
3
4
|
it { is_expected.to respond_to(:configure) }
|
|
@@ -10,12 +11,24 @@ describe ActiveFedora::Noid do
|
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
describe '#treeify' do
|
|
13
|
-
subject {
|
|
14
|
+
subject { described_class.treeify(id) }
|
|
14
15
|
let(:id) { 'abc123def45' }
|
|
15
16
|
it { is_expected.to eq 'ab/c1/23/de/abc123def45' }
|
|
16
17
|
context 'with a seven-digit identifier' do
|
|
17
18
|
let(:id) { 'abc123z' }
|
|
18
19
|
it { is_expected.to eq 'ab/c1/23/z/abc123z' }
|
|
19
20
|
end
|
|
21
|
+
context 'with an empty string' do
|
|
22
|
+
let(:id) { '' }
|
|
23
|
+
it 'raises ArgumentError' do
|
|
24
|
+
expect { subject }.to raise_error(ArgumentError)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
context 'with a nil' do
|
|
28
|
+
let(:id) { nil }
|
|
29
|
+
it 'raises ArgumentError' do
|
|
30
|
+
expect { subject }.to raise_error(ArgumentError)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
20
33
|
end
|
|
21
34
|
end
|
data/spec/unit/service_spec.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
describe ActiveFedora::Noid::Service do
|
|
2
3
|
describe 'public API' do
|
|
3
4
|
it { is_expected.to respond_to(:valid?) }
|
|
@@ -11,7 +12,7 @@ describe ActiveFedora::Noid::Service do
|
|
|
11
12
|
context 'with a custom minter' do
|
|
12
13
|
let(:minter) { double('minter') }
|
|
13
14
|
let(:identifier) { 'abc123' }
|
|
14
|
-
let(:new_service) {
|
|
15
|
+
let(:new_service) { described_class.new(minter) }
|
|
15
16
|
|
|
16
17
|
it 'allows injecting a custom minter' do
|
|
17
18
|
expect(new_service.minter).to eq minter
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_fedora-noid
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.0.
|
|
4
|
+
version: 2.0.0.beta6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael J. Giarlo
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-10-
|
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: active-fedora
|
|
@@ -120,6 +120,34 @@ dependencies:
|
|
|
120
120
|
- - ">="
|
|
121
121
|
- !ruby/object:Gem::Version
|
|
122
122
|
version: '0'
|
|
123
|
+
- !ruby/object:Gem::Dependency
|
|
124
|
+
name: rubocop
|
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
|
126
|
+
requirements:
|
|
127
|
+
- - "~>"
|
|
128
|
+
- !ruby/object:Gem::Version
|
|
129
|
+
version: 0.42.0
|
|
130
|
+
type: :development
|
|
131
|
+
prerelease: false
|
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
133
|
+
requirements:
|
|
134
|
+
- - "~>"
|
|
135
|
+
- !ruby/object:Gem::Version
|
|
136
|
+
version: 0.42.0
|
|
137
|
+
- !ruby/object:Gem::Dependency
|
|
138
|
+
name: rubocop-rspec
|
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
|
140
|
+
requirements:
|
|
141
|
+
- - "~>"
|
|
142
|
+
- !ruby/object:Gem::Version
|
|
143
|
+
version: '1.5'
|
|
144
|
+
type: :development
|
|
145
|
+
prerelease: false
|
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
147
|
+
requirements:
|
|
148
|
+
- - "~>"
|
|
149
|
+
- !ruby/object:Gem::Version
|
|
150
|
+
version: '1.5'
|
|
123
151
|
- !ruby/object:Gem::Dependency
|
|
124
152
|
name: engine_cart
|
|
125
153
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -143,6 +171,8 @@ extra_rdoc_files: []
|
|
|
143
171
|
files:
|
|
144
172
|
- ".gitignore"
|
|
145
173
|
- ".rspec"
|
|
174
|
+
- ".rubocop.yml"
|
|
175
|
+
- ".rubocop_todo.yml"
|
|
146
176
|
- ".travis.yml"
|
|
147
177
|
- CONTRIBUTING.md
|
|
148
178
|
- Gemfile
|