hydra-remote_identifier 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hydra/remote_identifier.rb +14 -0
- data/lib/hydra/remote_identifier/registration.rb +5 -2
- data/lib/hydra/remote_identifier/remote_service.rb +9 -0
- data/lib/hydra/remote_identifier/version.rb +1 -1
- data/spec/lib/hydra/remote_identifier/registration_spec.rb +12 -1
- data/spec/lib/hydra/remote_identifier/remote_service_spec.rb +3 -0
- data/spec/lib/hydra/remote_identifier_spec.rb +25 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00609ca00a1aa3d266e11024d3e68b755716d609
|
4
|
+
data.tar.gz: d9fcb87871a336c9850fd913585296cc75951200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbfdc77f38b4d7031246bd72e525701cb2888882f304bc376800d76bb52e1fec61890f9941e60ec61567bb4e92749cca9928e458d85170b49e9c30faf0fff203
|
7
|
+
data.tar.gz: 56fd2f04082c9b23390e900e07ef27273053c955a4ded0c0b9bf5c938173fab3fbc99d5fef7085ff656d6a23a5103708c3ce2ad4fe6cf44227fcf277e8a23d3f
|
@@ -31,6 +31,20 @@ module Hydra::RemoteIdentifier
|
|
31
31
|
yield(configuration)
|
32
32
|
end
|
33
33
|
|
34
|
+
# @example
|
35
|
+
# Hydra::RemoteIdentifier.with_registered_remote_service(:doi, book) do |remote_service|
|
36
|
+
# Hydra::RemoteIdentifier.mint(:doi, book)
|
37
|
+
# end
|
38
|
+
def with_registered_remote_service(service_name, target)
|
39
|
+
# @TODO - the registered remote identifier is more than a bit off;
|
40
|
+
# but it continues to work
|
41
|
+
target.registered_remote_identifier_minters.each {|minter|
|
42
|
+
if minter.remote_service.name.to_s == service_name.to_s
|
43
|
+
yield(minter.remote_service)
|
44
|
+
end
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
34
48
|
# Using the RemoteService mint the corresponding remote identifier for
|
35
49
|
# the target. You must first configure the RemoteService and target's class
|
36
50
|
# to define the attribute map. See Hydra::RemoteIdentifier.configure
|
@@ -24,8 +24,11 @@ module Hydra::RemoteIdentifier
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def register_target(target_class, &map)
|
27
|
-
|
28
|
-
target_class.
|
27
|
+
target_class.module_exec(remote_service) do |service|
|
28
|
+
unless target_class.respond_to?(:registered_remote_identifier_minters)
|
29
|
+
class_attribute :registered_remote_identifier_minters
|
30
|
+
end
|
31
|
+
attr_accessor service.accessor_name
|
29
32
|
end
|
30
33
|
target_class.registered_remote_identifier_minters ||= []
|
31
34
|
target_class.registered_remote_identifier_minters += [minting_coordinator.new(remote_service, &map)]
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
1
2
|
module Hydra::RemoteIdentifier
|
2
3
|
|
3
4
|
# The RemoteService is responsible for delivering a payload to a remote
|
@@ -7,6 +8,14 @@ module Hydra::RemoteIdentifier
|
|
7
8
|
# payload.
|
8
9
|
class RemoteService
|
9
10
|
|
11
|
+
def name
|
12
|
+
self.class.to_s.demodulize.underscore.to_sym
|
13
|
+
end
|
14
|
+
|
15
|
+
def accessor_name
|
16
|
+
"mint_#{name}".to_sym
|
17
|
+
end
|
18
|
+
|
10
19
|
def valid_attribute?(attribute_name)
|
11
20
|
raise NotImplementedError,
|
12
21
|
"You must implement #{self.class}#valid_attribute?"
|
@@ -4,16 +4,27 @@ module Hydra::RemoteIdentifier
|
|
4
4
|
describe Registration do
|
5
5
|
let(:minting_coordinator) { double(new: :minting_coordinator) }
|
6
6
|
let(:target_class) { Class.new }
|
7
|
+
let(:remote_service) { double(accessor_name: :mint_my_remote_service) }
|
7
8
|
let(:map) { lambda {|m| m.title :title } }
|
8
|
-
subject { Registration.new(
|
9
|
+
subject { Registration.new(remote_service, minting_coordinator) }
|
10
|
+
|
9
11
|
it 'requires a map' do
|
10
12
|
expect { subject.register(target_class) }.to raise_error(RuntimeError)
|
11
13
|
end
|
14
|
+
|
12
15
|
it 'adds a .registered_remote_identifier_minters method' do
|
13
16
|
expect {
|
14
17
|
subject.register(target_class, &map)
|
15
18
|
}.to change{ target_class.respond_to?(:registered_remote_identifier_minters) }.from(false).to(true)
|
16
19
|
end
|
20
|
+
|
21
|
+
it 'adds a #mint_remote_service attribute' do
|
22
|
+
subject.register(target_class, &map)
|
23
|
+
target = target_class.new
|
24
|
+
expect(target).to respond_to(:mint_my_remote_service)
|
25
|
+
expect(target).to respond_to(:mint_my_remote_service=)
|
26
|
+
end
|
27
|
+
|
17
28
|
it 'registers the minting coordinator on the target class' do
|
18
29
|
subject.register(target_class, &map)
|
19
30
|
expect(target_class.registered_remote_identifier_minters).to eq [:minting_coordinator]
|
@@ -7,6 +7,9 @@ module Hydra::RemoteIdentifier
|
|
7
7
|
let(:payload) { 'abc' }
|
8
8
|
subject { RemoteService.new }
|
9
9
|
|
10
|
+
its(:name) { should eq :remote_service }
|
11
|
+
its(:accessor_name) { should eq :mint_remote_service }
|
12
|
+
|
10
13
|
context '#call' do
|
11
14
|
it { expect { subject.call(payload) }.to raise_error NotImplementedError }
|
12
15
|
end
|
@@ -2,7 +2,21 @@ require 'spec_helper'
|
|
2
2
|
require File.expand_path('../../../../lib/hydra/remote_identifier', __FILE__)
|
3
3
|
module Hydra::RemoteIdentifier
|
4
4
|
|
5
|
-
describe '
|
5
|
+
describe 'public API' do
|
6
|
+
before(:each) do
|
7
|
+
Hydra::RemoteIdentifier.configure do |config|
|
8
|
+
config.remote_service(:doi, doi_options) do |doi|
|
9
|
+
doi.register(target_class) do |map|
|
10
|
+
map.target :url
|
11
|
+
map.creator :creator
|
12
|
+
map.title :title
|
13
|
+
map.publisher :publisher
|
14
|
+
map.publicationyear :publicationyear
|
15
|
+
map.set_identifier(:set_identifier=)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
6
20
|
|
7
21
|
let(:target_class) {
|
8
22
|
Class.new {
|
@@ -31,23 +45,18 @@ module Hydra::RemoteIdentifier
|
|
31
45
|
}
|
32
46
|
}
|
33
47
|
|
34
|
-
describe '.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
map.target :url
|
41
|
-
map.creator :creator
|
42
|
-
map.title :title
|
43
|
-
map.publisher :publisher
|
44
|
-
map.publicationyear :publicationyear
|
45
|
-
map.set_identifier(:set_identifier=)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
48
|
+
describe '.with_remote_service' do
|
49
|
+
|
50
|
+
it 'should yield the service if one is registered' do
|
51
|
+
expect {|block|
|
52
|
+
Hydra::RemoteIdentifier.with_registered_remote_service(:doi, target, &block)
|
53
|
+
}.to yield_with_args(RemoteServices::Doi)
|
49
54
|
end
|
50
55
|
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '.register' do
|
59
|
+
|
51
60
|
it 'works!', VCR::SpecSupport.merge(record: :new_episodes, cassette_name: 'doi-integration') do
|
52
61
|
expect {
|
53
62
|
Hydra::RemoteIdentifier.mint(:doi, target)
|