hydra-remote_identifier 0.2.2 → 0.3.0

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: 00609ca00a1aa3d266e11024d3e68b755716d609
4
- data.tar.gz: d9fcb87871a336c9850fd913585296cc75951200
3
+ metadata.gz: 3ab26b285d7aa330263fb086b0bc280448b9e7b0
4
+ data.tar.gz: cbcd41fd1cf8a074c30a1a7c5ff1c48028b8aef6
5
5
  SHA512:
6
- metadata.gz: cbfdc77f38b4d7031246bd72e525701cb2888882f304bc376800d76bb52e1fec61890f9941e60ec61567bb4e92749cca9928e458d85170b49e9c30faf0fff203
7
- data.tar.gz: 56fd2f04082c9b23390e900e07ef27273053c955a4ded0c0b9bf5c938173fab3fbc99d5fef7085ff656d6a23a5103708c3ce2ad4fe6cf44227fcf277e8a23d3f
6
+ metadata.gz: 36d568e724f9b87055c8ac453f64d25b57b0c221d478fce22ef03468b797d6758ed5ca0c571f627993eef923006b1d62a525e8a63f254c0a76a91dfd0914a20a
7
+ data.tar.gz: 46403c9ec84143ec5ae66c3ba072a582858d9b493281ff502b208d8c72a30230205b40dd7e5d3e55e87341d3aaabc6674523a139debfe6fd5d1f7d96f4fb8945
@@ -35,16 +35,25 @@ module Hydra::RemoteIdentifier
35
35
  # Hydra::RemoteIdentifier.with_registered_remote_service(:doi, book) do |remote_service|
36
36
  # Hydra::RemoteIdentifier.mint(:doi, book)
37
37
  # end
38
- def with_registered_remote_service(service_name, target)
38
+ def with_registered_remote_service(remote_service_name, target)
39
39
  # @TODO - the registered remote identifier is more than a bit off;
40
40
  # but it continues to work
41
41
  target.registered_remote_identifier_minters.each {|minter|
42
- if minter.remote_service.name.to_s == service_name.to_s
42
+ if minter.remote_service.name.to_s == remote_service_name.to_s
43
43
  yield(minter.remote_service)
44
44
  end
45
45
  }
46
46
  end
47
47
 
48
+ def mint_if_applicable(remote_service_name, target)
49
+ remote_service = configuration.find_remote_service(remote_service_name)
50
+ if target.public_send(remote_service.accessor_name).to_i != 0
51
+ target.registered_remote_identifier_minters.each do |minter|
52
+ minter.call(target) if minter.remote_service == remote_service
53
+ end
54
+ end
55
+ end
56
+
48
57
  # Using the RemoteService mint the corresponding remote identifier for
49
58
  # the target. You must first configure the RemoteService and target's class
50
59
  # to define the attribute map. See Hydra::RemoteIdentifier.configure
@@ -12,6 +12,14 @@ module Hydra::RemoteIdentifier
12
12
  self.class.to_s.demodulize.underscore.to_sym
13
13
  end
14
14
 
15
+ def mint(target)
16
+ Hydra::RemoteIdentifier.mint(name, target)
17
+ end
18
+
19
+ def mint_if_applicable(target)
20
+ Hydra::RemoteIdentifier.mint_if_applicable(name, target)
21
+ end
22
+
15
23
  def accessor_name
16
24
  "mint_#{name}".to_sym
17
25
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module RemoteIdentifier
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -18,6 +18,20 @@ module Hydra::RemoteIdentifier
18
18
  it { expect { subject.valid_attribute?(:attribute_name) }.to raise_error NotImplementedError }
19
19
  end
20
20
 
21
+ context '#mint' do
22
+ it {
23
+ Hydra::RemoteIdentifier.should_receive(:mint).with(:remote_service, :target)
24
+ subject.mint(:target)
25
+ }
26
+ end
27
+
28
+ context '#mint_if_applicable' do
29
+ it {
30
+ Hydra::RemoteIdentifier.should_receive(:mint_if_applicable).with(:remote_service, :target)
31
+ subject.mint_if_applicable(:target)
32
+ }
33
+ end
34
+
21
35
  end
22
36
 
23
37
  end
@@ -53,9 +53,15 @@ 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
57
+ expect {|block|
58
+ Hydra::RemoteIdentifier.with_registered_remote_service(:alternate, target, &block)
59
+ }.to_not yield_control
60
+ end
61
+
56
62
  end
57
63
 
58
- describe '.register' do
64
+ describe '.mint' do
59
65
 
60
66
  it 'works!', VCR::SpecSupport.merge(record: :new_episodes, cassette_name: 'doi-integration') do
61
67
  expect {
@@ -65,6 +71,24 @@ module Hydra::RemoteIdentifier
65
71
 
66
72
  end
67
73
 
74
+ describe '.mint_if_applicable' do
75
+
76
+ it 'does not mint if accessor is not set' do
77
+ target.mint_doi = '0'
78
+ expect {
79
+ Hydra::RemoteIdentifier.mint_if_applicable(:doi, target)
80
+ }.to_not change(target, :set_identifier)
81
+ end
82
+
83
+ it 'mints if accessor is set to non-zero', VCR::SpecSupport.merge(record: :new_episodes, cassette_name: 'doi-integration') do
84
+ target.mint_doi = '1'
85
+ expect {
86
+ Hydra::RemoteIdentifier.mint_if_applicable(:doi, target)
87
+ }.to change(target, :set_identifier).from(nil).to(expected_doi)
88
+ end
89
+
90
+ end
91
+
68
92
  end
69
93
 
70
94
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-remote_identifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-07 00:00:00.000000000 Z
11
+ date: 2013-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport