hydra-remote_identifier 0.5.1 → 0.5.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: 68f852f82865fce51183e6cf178e7ec15cf7cae4
4
- data.tar.gz: 5d453454a68027663297d5ee16548590630c1eeb
3
+ metadata.gz: cd5ebaf5e75ba163755a2f32c2c68be67356055c
4
+ data.tar.gz: 044e7aa00ad6079cb05f47251b48782b29061fe3
5
5
  SHA512:
6
- metadata.gz: 3dda3e9b63f470fae42a7c37fc791045c59f0fe8a36cf8142d3e59a38289d6ee48277888f5c21d308bcfdd89103a34baf3c2e02d33f4cf421917e39c3a354ea7
7
- data.tar.gz: c3508551c81a135bb5d33b48b3c378df5e92db3312404753c1f4694f63a553adda1557a5495ffded296d877ec3375676dc977a2a76c3f215295bdc0b34907fce
6
+ metadata.gz: e3fe0b25361efc0dad12e9cd85587423221412acea745ba7df2145e85ec387108e1518bb929bdc0a05d820fccfe28c77485dc949d58fd89002458d4887531fa6
7
+ data.tar.gz: ca390ae0f68802254da1839102e468fe69d81ddb21a59a38902ac1c51ffa8a2557d79eae83623d209c67c3fd6ae68a62926651fca457826708cf02fcce97c717
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/hydra-remote_identifier.png)](http://badge.fury.io/rb/hydra-remote_identifier)
4
4
  [![Build Status](https://travis-ci.org/jeremyf/hydra-remote_identifier.png)](https://travis-ci.org/jeremyf/hydra-remote_identifier)
5
5
 
6
-
7
6
  Coordinate the registration and minting of remote identifiers for persisted
8
7
  objects.
9
8
 
@@ -42,9 +41,10 @@ end
42
41
  ```
43
42
 
44
43
  If you are using Rails, you can run `rails generate hydra:remote_identifier:install` to
45
- create a Rails initializer with the above stub file.
44
+ create a Rails initializer with a configuration stub file. Also available is
45
+ `rails generate hydra:remote_identifier:doi`.
46
46
 
47
- In your views allow users to request that a remote identifier be assigned:
47
+ In your views allow users to request that a remote identifier be created/assigned:
48
48
 
49
49
  ```ruby
50
50
  <%= form_for book do |f| %>
@@ -14,6 +14,7 @@ class Hydra::RemoteIdentifier::DoiGenerator < Rails::Generators::Base
14
14
  argument :targets, :type => :array, :default => [], :banner => "class_name class_name"
15
15
 
16
16
  def insert_doi
17
+
17
18
  inject_into_file(
18
19
  "config/initializers/hydra-remote_identifier_config.rb",
19
20
  after: /Hydra::RemoteIdentifier.*/
@@ -17,7 +17,7 @@ module Hydra::RemoteIdentifier
17
17
  attr_reader :remote_services
18
18
 
19
19
  def find_remote_service(service_name)
20
- remote_services.fetch(service_name)
20
+ remote_services.fetch(service_name.to_sym)
21
21
  end
22
22
 
23
23
  # @param service_name [#to_s]
@@ -25,14 +25,17 @@ module Hydra::RemoteIdentifier
25
25
  #
26
26
  # @yieldparam [Registration]
27
27
  def remote_service(service_name, *args)
28
- remote_service = remote_service_class_lookup(service_name).new(*args)
29
- remote_services[service_name] = remote_service
28
+ remote_service = find_or_store_remote_service(service_name, *args)
30
29
  registration = registration_builder.new(remote_service)
31
30
  yield(registration)
32
31
  remote_service
33
32
  end
34
33
 
35
34
  private
35
+ def find_or_store_remote_service(service_name, *args)
36
+ remote_services[service_name.to_sym] ||= remote_service_class_lookup(service_name).new(*args)
37
+ remote_services.fetch(service_name.to_sym)
38
+ end
36
39
 
37
40
  def remote_service_class_lookup(string)
38
41
  remote_service_class_name = string.to_s.gsub(/(?:^|_)([a-z])/) { $1.upcase }
@@ -27,6 +27,7 @@ module Hydra::RemoteIdentifier
27
27
 
28
28
  def update_target(identifier)
29
29
  target.set_identifier(identifier)
30
+ identifier
30
31
  end
31
32
 
32
33
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module RemoteIdentifier
3
- VERSION = "0.5.1"
3
+ VERSION = "0.5.2"
4
4
  end
5
5
  end
@@ -108,12 +108,11 @@ module Hydra::RemoteIdentifier
108
108
  # @param target [#registered_remote_identifier_minters]
109
109
  def mint(remote_service_name, target)
110
110
  return false unless target.respond_to?(:registered_remote_identifier_minters)
111
-
112
- # @TODO - there is a better way to do this but this is "complete/correct"
113
111
  remote_service = configuration.find_remote_service(remote_service_name)
114
- target.registered_remote_identifier_minters.each do |coordinator|
115
- coordinator.call(target) if coordinator.remote_service == remote_service
112
+ coordinator = target.registered_remote_identifier_minters.detect do |c|
113
+ c.remote_service.name == remote_service.name
116
114
  end
115
+ coordinator.call(target) if coordinator
117
116
  end
118
117
 
119
118
  end
@@ -17,7 +17,7 @@ module Hydra::RemoteIdentifier
17
17
  it "extracts the target's payload to send to the remote service then updates the target's identifier" do
18
18
  service.should_receive(:call).with(payload).and_return(identifier)
19
19
  target.should_receive(:set_identifier).with(identifier)
20
- subject.call
20
+ expect(subject.call).to eq(identifier)
21
21
  end
22
22
  end
23
23
 
@@ -9,8 +9,8 @@ module Hydra::RemoteIdentifier
9
9
  subject { MintingCoordinator.new(remote_service, mapper_builder, &map) }
10
10
  it 'forward delegates call to the minter' do
11
11
  minter = double
12
- minter.should_receive(:call).with(remote_service, :wrapped_target)
13
- subject.call(target, minter)
12
+ minter.should_receive(:call).with(remote_service, :wrapped_target).and_return(:response)
13
+ expect(subject.call(target, minter)).to eq(:response)
14
14
  end
15
15
  end
16
16
  end
@@ -93,6 +93,10 @@ module Hydra::RemoteIdentifier
93
93
  }.to change(target, :set_identifier).from(nil).to(expected_doi)
94
94
  end
95
95
 
96
+ it 'returns the newly minted identifier', VCR::SpecSupport(record: :new_episodes, cassette_name: 'doi-integration') do
97
+ expect(Hydra::RemoteIdentifier.mint(:doi, target)).to eq(expected_doi)
98
+ end
99
+
96
100
  it 'returns false if the target is not configured for identifiers' do
97
101
  expect(Hydra::RemoteIdentifier.mint(:doi, double)).to eq(false)
98
102
  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.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen