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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10836a31b160f5f0061cb2d18a6ccce899434f52
4
- data.tar.gz: feb33ac8e38e21c1bc001207d17ce834ef4c620e
3
+ metadata.gz: 00609ca00a1aa3d266e11024d3e68b755716d609
4
+ data.tar.gz: d9fcb87871a336c9850fd913585296cc75951200
5
5
  SHA512:
6
- metadata.gz: b7cc709cba8c837303e438c6b71d369a49eb995ba17023dbef89f9814be236f59de0aa7decbf930541590cc6283da0781b9952267bcab1e8d5b21f4ff24d03ae
7
- data.tar.gz: e7181ea4930d62f5c83c6886d49903c2566ead86ac600b615d8040749347bb809de0edf95673d053f38fb2125e9071c5a15d3e58f43c3b9989a7a27b1ed94153
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
- unless target_class.respond_to?(:registered_remote_identifier_minters)
28
- target_class.class_attribute :registered_remote_identifier_minters
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?"
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module RemoteIdentifier
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -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(:my_remote_service, minting_coordinator) }
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 '.configure' do
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 '.register API' do
35
-
36
- before(:each) do
37
- Hydra::RemoteIdentifier.configure do |config|
38
- config.remote_service(:doi, doi_options) do |doi|
39
- doi.register(target_class) do |map|
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)
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen