hydra-remote_identifier 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/hydra/remote_identifier.rb +19 -1
- data/lib/hydra/remote_identifier/configuration.rb +10 -11
- data/lib/hydra/remote_identifier/version.rb +1 -1
- data/spec/lib/hydra/remote_identifier/configuration_spec.rb +16 -18
- data/spec/lib/hydra/remote_identifier/registration_spec.rb +1 -1
- data/spec/lib/hydra/remote_identifier/remote_service_spec.rb +9 -4
- data/spec/lib/hydra/remote_identifier_spec.rb +3 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10836a31b160f5f0061cb2d18a6ccce899434f52
|
4
|
+
data.tar.gz: feb33ac8e38e21c1bc001207d17ce834ef4c620e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7cc709cba8c837303e438c6b71d369a49eb995ba17023dbef89f9814be236f59de0aa7decbf930541590cc6283da0781b9952267bcab1e8d5b21f4ff24d03ae
|
7
|
+
data.tar.gz: e7181ea4930d62f5c83c6886d49903c2566ead86ac600b615d8040749347bb809de0edf95673d053f38fb2125e9071c5a15d3e58f43c3b9989a7a27b1ed94153
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Hydra::RemoteIdentifier
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/hydra-remote_identifier.png)](http://badge.fury.io/rb/hydra-remote_identifier)
|
4
|
+
|
3
5
|
Coordinate the registration and minting of remote identifiers for persisted
|
4
6
|
objects.
|
5
7
|
|
@@ -23,8 +25,8 @@ Configure your remote identifiers with credentials and what have you:
|
|
23
25
|
|
24
26
|
doi_credentials = Psych.load('/path/to/doi_credentials.yml')
|
25
27
|
Hydra::RemoteIdentifier.configure do |config|
|
26
|
-
config.
|
27
|
-
doi.register(
|
28
|
+
config.remote_service(:doi, doi_credentials) do |doi|
|
29
|
+
doi.register(Book, Page) do |map|
|
28
30
|
map.target :url
|
29
31
|
map.creator :creator
|
30
32
|
map.title :title
|
@@ -12,7 +12,7 @@ module Hydra::RemoteIdentifier
|
|
12
12
|
#
|
13
13
|
# @example
|
14
14
|
# Hydra::RemoteIdentifier.configure do |config|
|
15
|
-
# config.
|
15
|
+
# config.remote_service(:doi, doi_credentials) do |doi|
|
16
16
|
# doi.register(target_class) do |map|
|
17
17
|
# map.target :url
|
18
18
|
# map.creator :creator
|
@@ -31,6 +31,24 @@ module Hydra::RemoteIdentifier
|
|
31
31
|
yield(configuration)
|
32
32
|
end
|
33
33
|
|
34
|
+
# Using the RemoteService mint the corresponding remote identifier for
|
35
|
+
# the target. You must first configure the RemoteService and target's class
|
36
|
+
# to define the attribute map. See Hydra::RemoteIdentifier.configure
|
37
|
+
#
|
38
|
+
#
|
39
|
+
# @example
|
40
|
+
# Hydra::RemoteIdentifier.mint(:doi, book)
|
41
|
+
#
|
42
|
+
# @param remote_service_name [#to_s]
|
43
|
+
# @param target [#registered_remote_identifier_minters]
|
44
|
+
def mint(remote_service_name, target)
|
45
|
+
# @TODO - there is a better way to do this but this is "complete/correct"
|
46
|
+
remote_service = configuration.find_remote_service(remote_service_name)
|
47
|
+
target.registered_remote_identifier_minters.each do |minter|
|
48
|
+
minter.call(target) if minter.remote_service == remote_service
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
34
52
|
end
|
35
53
|
|
36
54
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path('../remote_services', __FILE__)
|
2
|
+
require File.expand_path('../registration', __FILE__)
|
2
3
|
|
3
4
|
module Hydra::RemoteIdentifier
|
4
5
|
|
@@ -7,25 +8,23 @@ module Hydra::RemoteIdentifier
|
|
7
8
|
class Configuration
|
8
9
|
|
9
10
|
def initialize(options = {})
|
10
|
-
@remote_service_namespace_container = options.fetch(:remote_service_namespace_container,
|
11
|
+
@remote_service_namespace_container = options.fetch(:remote_service_namespace_container, RemoteServices)
|
12
|
+
@registration_builder = options.fetch(:registration_builder, Registration)
|
11
13
|
@remote_services = {}
|
12
14
|
end
|
13
|
-
attr_reader :remote_service_namespace_container
|
14
|
-
private :remote_service_namespace_container
|
15
|
+
attr_reader :remote_service_namespace_container, :registration_builder
|
16
|
+
private :remote_service_namespace_container, :registration_builder
|
15
17
|
attr_reader :remote_services
|
16
18
|
|
17
19
|
def find_remote_service(service_name)
|
18
|
-
remote_services.fetch(service_name
|
20
|
+
remote_services.fetch(service_name)
|
19
21
|
end
|
20
22
|
|
21
|
-
def remote_service(service_name, *args
|
22
|
-
remote_service_class_lookup(service_name).configure(*args, &block)
|
23
|
-
end
|
24
|
-
|
25
|
-
def configure_remote_service(service_name, *args, &block)
|
23
|
+
def remote_service(service_name, *args)
|
26
24
|
remote_service = remote_service_class_lookup(service_name).new(*args)
|
27
|
-
remote_services[service_name]
|
28
|
-
|
25
|
+
remote_services[service_name] = remote_service
|
26
|
+
registration = registration_builder.new(remote_service)
|
27
|
+
yield(registration)
|
29
28
|
remote_service
|
30
29
|
end
|
31
30
|
|
@@ -6,11 +6,9 @@ module Hydra::RemoteIdentifier
|
|
6
6
|
around do |example|
|
7
7
|
module RemoteServices
|
8
8
|
class MyRemoteService
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@options = [args, block]
|
13
|
-
end
|
9
|
+
attr_reader :options
|
10
|
+
def initialize(*options)
|
11
|
+
@options = options
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
@@ -18,15 +16,19 @@ module Hydra::RemoteIdentifier
|
|
18
16
|
RemoteServices.send(:remove_const, :MyRemoteService)
|
19
17
|
end
|
20
18
|
|
21
|
-
subject { Configuration.new }
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
subject { Configuration.new(registration_builder: registration_builder) }
|
20
|
+
let(:registration_builder) {
|
21
|
+
Class.new do
|
22
|
+
attr_reader :remote_service
|
23
|
+
def initialize(remote_service)
|
24
|
+
@remote_service = remote_service
|
25
|
+
end
|
26
26
|
end
|
27
|
+
}
|
28
|
+
context 'with a missing service' do
|
27
29
|
specify do
|
28
30
|
expect {
|
29
|
-
subject.
|
31
|
+
subject.remote_service(:obviously_missing_service)
|
30
32
|
}.to raise_error(NotImplementedError)
|
31
33
|
end
|
32
34
|
end
|
@@ -34,15 +36,11 @@ module Hydra::RemoteIdentifier
|
|
34
36
|
context 'with an existing service' do
|
35
37
|
let(:block) { lambda {} }
|
36
38
|
specify do
|
37
|
-
expect {
|
38
|
-
subject.remote_service(:my_remote_service,
|
39
|
-
}.to
|
40
|
-
end
|
41
|
-
specify do
|
42
|
-
expect(subject.find_remote_service(:my_remote_service)).to be_an_instance_of(RemoteServices::MyRemoteService)
|
39
|
+
expect {|reg|
|
40
|
+
subject.remote_service(:my_remote_service, ®)
|
41
|
+
}.to yield_with_args(registration_builder)
|
43
42
|
end
|
44
43
|
end
|
45
|
-
|
46
44
|
end
|
47
45
|
|
48
46
|
end
|
@@ -14,7 +14,7 @@ module Hydra::RemoteIdentifier
|
|
14
14
|
subject.register(target_class, &map)
|
15
15
|
}.to change{ target_class.respond_to?(:registered_remote_identifier_minters) }.from(false).to(true)
|
16
16
|
end
|
17
|
-
it '
|
17
|
+
it 'registers the minting coordinator on the target class' do
|
18
18
|
subject.register(target_class, &map)
|
19
19
|
expect(target_class.registered_remote_identifier_minters).to eq [:minting_coordinator]
|
20
20
|
end
|
@@ -4,12 +4,17 @@ module Hydra::RemoteIdentifier
|
|
4
4
|
|
5
5
|
describe RemoteService do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
let(:payload) { 'abc' }
|
8
|
+
subject { RemoteService.new }
|
9
|
+
|
10
|
+
context '#call' do
|
10
11
|
it { expect { subject.call(payload) }.to raise_error NotImplementedError }
|
12
|
+
end
|
13
|
+
|
14
|
+
context '#valid_attribute?' do
|
11
15
|
it { expect { subject.valid_attribute?(:attribute_name) }.to raise_error NotImplementedError }
|
12
16
|
end
|
17
|
+
|
13
18
|
end
|
14
19
|
|
15
|
-
end
|
20
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require File.expand_path('../../../../lib/hydra/remote_identifier', __FILE__)
|
2
3
|
module Hydra::RemoteIdentifier
|
3
4
|
|
@@ -34,7 +35,7 @@ module Hydra::RemoteIdentifier
|
|
34
35
|
|
35
36
|
before(:each) do
|
36
37
|
Hydra::RemoteIdentifier.configure do |config|
|
37
|
-
config.
|
38
|
+
config.remote_service(:doi, doi_options) do |doi|
|
38
39
|
doi.register(target_class) do |map|
|
39
40
|
map.target :url
|
40
41
|
map.creator :creator
|
@@ -49,9 +50,7 @@ module Hydra::RemoteIdentifier
|
|
49
50
|
|
50
51
|
it 'works!', VCR::SpecSupport.merge(record: :new_episodes, cassette_name: 'doi-integration') do
|
51
52
|
expect {
|
52
|
-
|
53
|
-
minter.call(target)
|
54
|
-
end
|
53
|
+
Hydra::RemoteIdentifier.mint(:doi, target)
|
55
54
|
}.to change(target, :set_identifier).from(nil).to(expected_doi)
|
56
55
|
end
|
57
56
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-remote_identifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Friesen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
requirements: []
|
147
147
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.0.
|
148
|
+
rubygems_version: 2.0.7
|
149
149
|
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: Handles the registration and minting of remote identifiers (i.e. DOI, ARK,
|