hydra-remote_identifier 0.4.0 → 0.4.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 +19 -0
- data/lib/hydra/remote_identifier.rb +21 -6
- data/lib/hydra/remote_identifier/remote_service.rb +4 -0
- data/lib/hydra/remote_identifier/version.rb +1 -1
- data/spec/lib/hydra/remote_identifier/remote_service_spec.rb +1 -0
- data/spec/lib/hydra/remote_identifier_spec.rb +1 -1
- 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: 9bfdfcaee94b94b71118befacfc086df017d23cf
|
4
|
+
data.tar.gz: 3e99f645cbd73f4217d5bd9ae50a4ef60a9ff254
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 236c6a8e16274abb3cd508b717a38f46b998ccc7c7c4d712f1d89ff846373ae82b8809f53b6628a0880f9bb0e77a48c34b75ececb9edaafb24b38c08defb6932
|
7
|
+
data.tar.gz: 529388f0a159d7eb9c6f3fee8ff9ded2468f7318ac858cddea6a2fdbc0aac0f6ee71af76647befd5f58a0861529dece024f8bd5e689ebb2bb7c7681247f037c3
|
data/README.md
CHANGED
@@ -36,3 +36,22 @@ Configure your remote identifiers with credentials and what have you:
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
In your views allow users to request that a remote identifier be assigned:
|
41
|
+
|
42
|
+
<%= form_for book do |f| %>
|
43
|
+
<% Hydra::RemoteIdentifier.with_registered_remote_service(:doi, f.object) do |remote_service| %>
|
44
|
+
<%= f.input remote_service.accessor_name %>
|
45
|
+
<% end %>
|
46
|
+
<% end %>
|
47
|
+
|
48
|
+
Where you enqueue an asynchronous worker iterate over the requested identifiers:
|
49
|
+
|
50
|
+
Hydra::RemoteIdentifier.applicable_remote_service_names_for(book) do |remote_service|
|
51
|
+
MintRemoteIdentifierWorker.enqueue(book.to_param, remote_service.name)
|
52
|
+
end
|
53
|
+
|
54
|
+
Where your asynchronouse worker does its work request the minting:
|
55
|
+
|
56
|
+
# Instantiate target from input
|
57
|
+
Hydra::RemoteIdentifier.mint(remote_service_name, target)
|
@@ -31,10 +31,16 @@ module Hydra::RemoteIdentifier
|
|
31
31
|
yield(configuration)
|
32
32
|
end
|
33
33
|
|
34
|
+
# Yields the specified RemoteService if it _could_ be requested for the
|
35
|
+
# Target.
|
36
|
+
#
|
34
37
|
# @example
|
35
|
-
# Hydra::RemoteIdentifier.with_registered_remote_service(:doi, book) do |remote_service|
|
36
|
-
#
|
37
|
-
# end
|
38
|
+
# <% Hydra::RemoteIdentifier.with_registered_remote_service(:doi, book) do |remote_service| %>
|
39
|
+
# <%= f.input remote_service.accessor_name %>
|
40
|
+
# <% end %>
|
41
|
+
#
|
42
|
+
# @param remote_service_name [#to_s]
|
43
|
+
# @param target [#registered_remote_identifier_minters] (see Hydra::RemoteIdentifier.configure)
|
38
44
|
def with_registered_remote_service(remote_service_name, target)
|
39
45
|
# @TODO - the registered remote identifier is more than a bit off;
|
40
46
|
# but it continues to work
|
@@ -45,11 +51,21 @@ module Hydra::RemoteIdentifier
|
|
45
51
|
}
|
46
52
|
end
|
47
53
|
|
54
|
+
|
55
|
+
# Yields each RemoteService#name that _is_ requested for the Target.
|
56
|
+
#
|
57
|
+
# @example
|
58
|
+
# Hydra::RemoteIdentifier.requested_remote_identifiers_for(book) do |remote_service_name|
|
59
|
+
# Hydra::RemoteIdentifier.mint(remote_service_name, book)
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# @param target [#registered_remote_identifier_minters] (see Hydra::RemoteIdentifier.configure)
|
63
|
+
# @yield_param remote_service_name [#to_s]
|
48
64
|
def requested_remote_identifiers_for(target)
|
49
65
|
target.registered_remote_identifier_minters.each do |coordinator|
|
50
66
|
remote_service = coordinator.remote_service
|
51
67
|
if target.public_send(remote_service.accessor_name).to_i != 0
|
52
|
-
yield(remote_service
|
68
|
+
yield(remote_service)
|
53
69
|
end
|
54
70
|
end
|
55
71
|
end
|
@@ -58,12 +74,11 @@ module Hydra::RemoteIdentifier
|
|
58
74
|
# the target. You must first configure the RemoteService and target's class
|
59
75
|
# to define the attribute map. See Hydra::RemoteIdentifier.configure
|
60
76
|
#
|
61
|
-
#
|
62
77
|
# @example
|
63
78
|
# Hydra::RemoteIdentifier.mint(:doi, book)
|
64
79
|
#
|
65
80
|
# @param remote_service_name [#to_s]
|
66
|
-
# @param target [#registered_remote_identifier_minters]
|
81
|
+
# @param target [#registered_remote_identifier_minters] (see Hydra::RemoteIdentifier.configure)
|
67
82
|
def mint(remote_service_name, target)
|
68
83
|
# @TODO - there is a better way to do this but this is "complete/correct"
|
69
84
|
remote_service = configuration.find_remote_service(remote_service_name)
|
@@ -9,6 +9,7 @@ module Hydra::RemoteIdentifier
|
|
9
9
|
|
10
10
|
its(:name) { should eq :remote_service }
|
11
11
|
its(:accessor_name) { should eq :mint_remote_service }
|
12
|
+
its(:to_s) { should eq 'remote_service' }
|
12
13
|
|
13
14
|
context '#call' do
|
14
15
|
it { expect { subject.call(payload) }.to raise_error NotImplementedError }
|
@@ -77,7 +77,7 @@ module Hydra::RemoteIdentifier
|
|
77
77
|
target.mint_doi = '1'
|
78
78
|
expect { |block|
|
79
79
|
Hydra::RemoteIdentifier.requested_remote_identifiers_for(target, &block)
|
80
|
-
}.to yield_with_args(
|
80
|
+
}.to yield_with_args(instance_of(RemoteServices::Doi))
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'should not yield when the remote identifier was not requested' do
|