hydra-remote_identifier 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bfdfcaee94b94b71118befacfc086df017d23cf
4
- data.tar.gz: 3e99f645cbd73f4217d5bd9ae50a4ef60a9ff254
3
+ metadata.gz: 6dd65def0770c56f479dbc71aaa0dc462603f1ad
4
+ data.tar.gz: d79fbb1d6ce12a804369a4ef441598c1effa2fbb
5
5
  SHA512:
6
- metadata.gz: 236c6a8e16274abb3cd508b717a38f46b998ccc7c7c4d712f1d89ff846373ae82b8809f53b6628a0880f9bb0e77a48c34b75ececb9edaafb24b38c08defb6932
7
- data.tar.gz: 529388f0a159d7eb9c6f3fee8ff9ded2468f7318ac858cddea6a2fdbc0aac0f6ee71af76647befd5f58a0861529dece024f8bd5e689ebb2bb7c7681247f037c3
6
+ metadata.gz: 29daa6481feda3dd6225bc112b38d6117c717ca50eac693bbe7a5f665c5958a8659fa400cb49f0e2e1bc0fff3da210d05b2358715bd932af99584e031142af7b
7
+ data.tar.gz: 72ccf7cd67fa4cca2dc617858a760530f2c06537a0e79efc9d2ef9ce62f798d91e84b5a2b378730c05ce4af1fcb0b547ecdb544f90824023aa846151992a14ae
data/README.md CHANGED
@@ -28,7 +28,7 @@ Configure your remote identifiers with credentials and what have you:
28
28
  config.remote_service(:doi, doi_credentials) do |doi|
29
29
  doi.register(Book, Page) do |map|
30
30
  map.target :url
31
- map.creator :creator
31
+ map.creator {|obj| obj.person_name }
32
32
  map.title :title
33
33
  map.publisher :publisher
34
34
  map.publicationyear :publicationyear
@@ -37,6 +37,9 @@ Configure your remote identifiers with credentials and what have you:
37
37
  end
38
38
  end
39
39
 
40
+ If you are using Rails, you can run `rails generate hydra:remote_identifier:install` to
41
+ create a Rails initializer with the above stub file.
42
+
40
43
  In your views allow users to request that a remote identifier be assigned:
41
44
 
42
45
  <%= form_for book do |f| %>
@@ -55,3 +58,25 @@ Where your asynchronouse worker does its work request the minting:
55
58
 
56
59
  # Instantiate target from input
57
60
  Hydra::RemoteIdentifier.mint(remote_service_name, target)
61
+
62
+ ## Extending Hydra::RemoteIdentifier with alternate remote identifiers
63
+
64
+ If you are interested in creating a new Hydra::RemoteIdentifier::RemoteService,
65
+ this can be done by creating a class in the Hydra::RemoteIdentifier::RemoteServices
66
+ namespace. See below:
67
+
68
+ module Hydra::RemoteIdentifier::RemoteServices
69
+ class MyRemoteService < Hydra::RemoteIdentifier::RemoteService
70
+ # your code here
71
+ end
72
+ end
73
+
74
+ Then configure your RemoteService for your persisted targets. See below:
75
+
76
+ Hydra::RemoteIdentifier.configure do |config|
77
+ config.remote_service(:my_remote_service, credentials) do |mine|
78
+ mine.register(Book, Page) do |map|
79
+ # map fields of Book, Page to the required payload for MyRemoteService
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,28 @@
1
+ require 'rails/generators'
2
+
3
+ class Hydra::RemoteIdentifier::InstallGenerator < Rails::Generators::Base
4
+ def create_config
5
+ initializer('hydra-remote_identifier_config.rb') do
6
+ data = []
7
+
8
+ data << '# Register and configure remote identifiers for persisted objects'
9
+ data << 'Hydra::RemoteIdentifier.configure do |config|'
10
+ data << ''
11
+ data << '# doi_credentials = Psych.load("/path/to/doi_credentials.yml")'
12
+ data << '# config.remote_service(:doi, doi_credentials) do |doi|'
13
+ data << '# doi.register(PersistedObject) do |map|'
14
+ data << '# map.target :url'
15
+ data << '# map.creator {|obj| obj.person_name }'
16
+ data << '# map.title :title'
17
+ data << '# map.publisher :publisher'
18
+ data << '# map.publicationyear :publicationyear'
19
+ data << '# map.set_identifier :set_doi_identifier='
20
+ data << '# end'
21
+ data << '# end'
22
+ data << ''
23
+ data << 'end'
24
+
25
+ data.join("\n")
26
+ end
27
+ end
28
+ end
@@ -2,6 +2,7 @@ require "hydra/remote_identifier/version"
2
2
  require 'hydra/remote_identifier/configuration'
3
3
  require 'hydra/remote_identifier/registration'
4
4
  require 'hydra/remote_identifier/remote_service'
5
+ require 'hydra/remote_identifier/railtie' if defined?(Rails)
5
6
 
6
7
  module Hydra::RemoteIdentifier
7
8
 
@@ -42,6 +43,7 @@ module Hydra::RemoteIdentifier
42
43
  # @param remote_service_name [#to_s]
43
44
  # @param target [#registered_remote_identifier_minters] (see Hydra::RemoteIdentifier.configure)
44
45
  def with_registered_remote_service(remote_service_name, target)
46
+ return false unless target.respond_to?(:registered_remote_identifier_minters)
45
47
  # @TODO - the registered remote identifier is more than a bit off;
46
48
  # but it continues to work
47
49
  target.registered_remote_identifier_minters.each {|coordinator|
@@ -62,6 +64,7 @@ module Hydra::RemoteIdentifier
62
64
  # @param target [#registered_remote_identifier_minters] (see Hydra::RemoteIdentifier.configure)
63
65
  # @yield_param remote_service_name [#to_s]
64
66
  def requested_remote_identifiers_for(target)
67
+ return false unless target.respond_to?(:registered_remote_identifier_minters)
65
68
  target.registered_remote_identifier_minters.each do |coordinator|
66
69
  remote_service = coordinator.remote_service
67
70
  if target.public_send(remote_service.accessor_name).to_i != 0
@@ -80,6 +83,8 @@ module Hydra::RemoteIdentifier
80
83
  # @param remote_service_name [#to_s]
81
84
  # @param target [#registered_remote_identifier_minters] (see Hydra::RemoteIdentifier.configure)
82
85
  def mint(remote_service_name, target)
86
+ return false unless target.respond_to?(:registered_remote_identifier_minters)
87
+
83
88
  # @TODO - there is a better way to do this but this is "complete/correct"
84
89
  remote_service = configuration.find_remote_service(remote_service_name)
85
90
  target.registered_remote_identifier_minters.each do |coordinator|
@@ -0,0 +1,7 @@
1
+ module Hydra::RemoteIdentifier
2
+ class Railtie < Rails::Railtie
3
+ generators do
4
+ require 'generators/hydra/remote_identifier/install_generator'
5
+ end
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module RemoteIdentifier
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
4
4
  end
5
5
  end
@@ -53,12 +53,19 @@ module Hydra::RemoteIdentifier
53
53
  }.to yield_with_args(RemoteServices::Doi)
54
54
  end
55
55
 
56
- it 'should not yield the service if non is registered' do
56
+ it 'should not yield the service is not registered' do
57
57
  expect {|block|
58
58
  Hydra::RemoteIdentifier.with_registered_remote_service(:alternate, target, &block)
59
59
  }.to_not yield_control
60
60
  end
61
61
 
62
+ it 'should not yield the service if the target is not registered' do
63
+ target = double
64
+ expect {|block|
65
+ Hydra::RemoteIdentifier.with_registered_remote_service(:doi, target, &block)
66
+ }.to_not yield_control
67
+ end
68
+
62
69
  end
63
70
 
64
71
  describe '.mint' do
@@ -69,6 +76,10 @@ module Hydra::RemoteIdentifier
69
76
  }.to change(target, :set_identifier).from(nil).to(expected_doi)
70
77
  end
71
78
 
79
+ it 'returns false if the target is not configured for identifiers' do
80
+ expect(Hydra::RemoteIdentifier.mint(:doi, double)).to eq(false)
81
+ end
82
+
72
83
  end
73
84
 
74
85
  describe '.requested_remote_identifiers_for' do
@@ -87,6 +98,13 @@ module Hydra::RemoteIdentifier
87
98
  }.to_not yield_control
88
99
  end
89
100
 
101
+ it 'should not yield when the remote identifier if target is not configured' do
102
+ target = double
103
+ expect { |block|
104
+ Hydra::RemoteIdentifier.requested_remote_identifiers_for(target, &block)
105
+ }.to_not yield_control
106
+ end
107
+
90
108
  end
91
109
 
92
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-remote_identifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
@@ -103,12 +103,14 @@ files:
103
103
  - README.md
104
104
  - Rakefile
105
105
  - hydra-remote_identifier.gemspec
106
+ - lib/generators/hydra/remote_identifier/install_generator.rb
106
107
  - lib/hydra/remote_identifier.rb
107
108
  - lib/hydra/remote_identifier/configuration.rb
108
109
  - lib/hydra/remote_identifier/exceptions.rb
109
110
  - lib/hydra/remote_identifier/mapper.rb
110
111
  - lib/hydra/remote_identifier/minter.rb
111
112
  - lib/hydra/remote_identifier/minting_coordinator.rb
113
+ - lib/hydra/remote_identifier/railtie.rb
112
114
  - lib/hydra/remote_identifier/registration.rb
113
115
  - lib/hydra/remote_identifier/remote_service.rb
114
116
  - lib/hydra/remote_identifier/remote_services.rb