hydra-remote_identifier 0.5.3 → 0.6.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: 3ad9b2a31edae34b37fafca1d7cef7292ff37bab
4
- data.tar.gz: 65e362d4c8eec8f4c1ecc20bcdf7fb75f5bb0c4c
3
+ metadata.gz: 99922dd154a6430c8dd64418d60db843a3f1082a
4
+ data.tar.gz: 0e6d029a6ae54490e3d5b6270469eb6a4ee57932
5
5
  SHA512:
6
- metadata.gz: aeb034f74327c96718859cea5ce998b7ec6f2c01bb4174c625067b44e68120a7e4cb25f4604043d8ce7dac19b03dd8499ece4183909b5f6dc77cf5385c2dc61f
7
- data.tar.gz: aa4f0b58c3c76c41222c6485dedc778551401ffbc6a8c06a80b68816af85138e5b1aaafcb7e04cab9a30ce41f6ed2b9992d04eaef9d35a0bec71618680d03825
6
+ metadata.gz: f22cacf89302908db05f330156f84f9a4145881b113ae1571e3e92338d3e8456e91b550af7860a53a74e39e9ab13f45ce7c05ad6ca3d02d11f968e405fcfd47f
7
+ data.tar.gz: 234cbd5325b35472d2d003f22bf5bc6ed3527b397548777cc643a5baaf7f29465962eab419dc808f1189fa09015cb88964829245af6c9ea875da4ad49e8c5e29
data/README.md CHANGED
@@ -48,7 +48,7 @@ In your views allow users to request that a remote identifier be created/assigne
48
48
 
49
49
  ```ruby
50
50
  <%= form_for book do |f| %>
51
- <% Hydra::RemoteIdentifier.with_registered_remote_service(:doi, f.object) do |remote_service| %>
51
+ <% Hydra::RemoteIdentifier.registered?(:doi, f.object) do |remote_service| %>
52
52
  <%= f.input remote_service.accessor_name %>
53
53
  <% end %>
54
54
  <% end %>
@@ -45,27 +45,50 @@ module Hydra::RemoteIdentifier
45
45
  end
46
46
  private :configure!
47
47
 
48
+ # Retrieve a valid RemoteService by name
49
+ # @example
50
+ # doi_remote_service = Hydra::RemoteIdentifier.remote_service(:doi)
51
+ #
52
+ # @param remote_service_name [#to_s]
53
+ # @returns [RemoteService]
54
+ def remote_service(remote_service_name)
55
+ configuration.find_remote_service(remote_service_name)
56
+ end
57
+
48
58
  # Yields the specified RemoteService if it _could_ be requested for the
49
59
  # Target.
50
60
  #
51
61
  # @example
52
- # <% Hydra::RemoteIdentifier.with_registered_remote_service(:doi, book) do |remote_service| %>
62
+ # <% Hydra::RemoteIdentifier.registered?(:doi, book) do |remote_service| %>
53
63
  # <%= f.input remote_service.accessor_name %>
54
64
  # <% end %>
55
65
  #
56
66
  # @param remote_service_name [#to_s]
57
67
  # @param target [#registered_remote_identifier_minters]
58
- def with_registered_remote_service(remote_service_name, target)
68
+ #
69
+ # @yieldparam @required first [RemoteService]
70
+ # @yieldparam @optional second [MintingCoordinator]
71
+ #
72
+ # @returns [Boolean]
73
+ def registered?(remote_service_name, target, &block)
59
74
  return false unless target.respond_to?(:registered_remote_identifier_minters)
60
- # @TODO - the registered remote identifier is more than a bit off;
61
- # but it continues to work
62
- target.registered_remote_identifier_minters.each {|coordinator|
63
- if coordinator.remote_service.name.to_s == remote_service_name.to_s
64
- yield(coordinator.remote_service)
75
+ !!target.registered_remote_identifier_minters.detect do |coordinator|
76
+ # require 'debugger'; debugger; true;
77
+ if coordinator.remote_service.to_s == remote_service_name.to_s
78
+ if block_given?
79
+ if block.arity == 2
80
+ block.call(coordinator.remote_service, coordinator)
81
+ else
82
+ block.call(coordinator.remote_service)
83
+ end
84
+ end
85
+ true
65
86
  end
66
- }
87
+ end
67
88
  end
68
89
 
90
+ alias_method :with_registered_remote_service, :registered?
91
+
69
92
  # @example
70
93
  # <%= link_to(object.doi, Hydra::RemoteIdentifier.remote_uri_for(:doi, object.doi)) %>
71
94
  #
@@ -107,14 +130,11 @@ module Hydra::RemoteIdentifier
107
130
  # @param remote_service_name [#to_s]
108
131
  # @param target [#registered_remote_identifier_minters]
109
132
  def mint(remote_service_name, target)
110
- return false unless target.respond_to?(:registered_remote_identifier_minters)
111
- remote_service = configuration.find_remote_service(remote_service_name)
112
- coordinator = target.registered_remote_identifier_minters.detect do |c|
113
- c.remote_service.name == remote_service.name
133
+ registered?(remote_service_name, target) do |remote_service, coordinator|
134
+ coordinator.call(target)
114
135
  end
115
- coordinator.call(target) if coordinator
116
136
  end
117
137
 
118
138
  end
119
139
 
120
- end
140
+ end
@@ -16,6 +16,14 @@ module Hydra::RemoteIdentifier
16
16
  name.to_s
17
17
  end
18
18
 
19
+ def registered?(target)
20
+ Hydra::RemoteIdentifier.registered?(self, target)
21
+ end
22
+
23
+ def mint(target)
24
+ Hydra::RemoteIdentifier.mint(self, target)
25
+ end
26
+
19
27
  # @param identifier[#to_s] - An identifier that was created by this remote
20
28
  # service
21
29
  # @returns [URI] - The URI for that identifier
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module RemoteIdentifier
3
- VERSION = "0.5.3"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -5,6 +5,7 @@ module Hydra::RemoteIdentifier
5
5
  describe RemoteService do
6
6
 
7
7
  let(:payload) { 'abc' }
8
+ let(:target) { double }
8
9
  subject { RemoteService.new }
9
10
 
10
11
  its(:name) { should eq :remote_service }
@@ -16,13 +17,25 @@ module Hydra::RemoteIdentifier
16
17
  end
17
18
 
18
19
  context '#remote_uri_for' do
19
- it { expect { subject.remote_uri_for(double) }.to raise_error NotImplementedError }
20
+ it { expect { subject.remote_uri_for(target) }.to raise_error NotImplementedError }
20
21
  end
21
22
 
22
23
  context '#valid_attribute?' do
23
24
  it { expect { subject.valid_attribute?(:attribute_name) }.to raise_error NotImplementedError }
24
25
  end
25
26
 
27
+ context '#mint' do
28
+ it 'should forward delegate to Hydra::RemoteService' do
29
+ Hydra::RemoteIdentifier.should_receive(:mint).with(subject, target)
30
+ subject.mint(target)
31
+ end
32
+ end
33
+ context '#registered?' do
34
+ it 'should forward delegate to Hydra::RemoteService' do
35
+ Hydra::RemoteIdentifier.should_receive(:registered?).with(subject, target).and_return(:returning_value)
36
+ expect(subject.registered?(target)).to eq(:returning_value)
37
+ end
38
+ end
26
39
  end
27
40
 
28
41
  end
@@ -35,11 +35,26 @@ module Hydra::RemoteIdentifier
35
35
  end
36
36
  end
37
37
 
38
+ context '.remote_service' do
39
+ it 'should return an instance of the request service' do
40
+ expect(Hydra::RemoteIdentifier.remote_service(:doi)).
41
+ to be_kind_of(RemoteServices::Doi)
42
+ end
43
+
44
+ it 'should raise exception if it is not a valid remote service' do
45
+ expect{
46
+ Hydra::RemoteIdentifier.remote_service(:alternate)
47
+ }.to raise_error(KeyError)
48
+ end
49
+ end
50
+
51
+
38
52
  context '.with_registered_remote_service' do
39
53
  it 'should yield the service if one is registered' do
40
- expect {|block|
41
- Hydra::RemoteIdentifier.with_registered_remote_service(:doi, target, &block)
42
- }.to yield_with_args(RemoteServices::Doi)
54
+ Hydra::RemoteIdentifier.with_registered_remote_service(:doi, target) do |arg1|
55
+ @arg1 = arg1
56
+ end
57
+ expect(@arg1).to be_instance_of(RemoteServices::Doi)
43
58
  end
44
59
 
45
60
  it 'should not yield the service is not registered' do
@@ -56,6 +71,41 @@ module Hydra::RemoteIdentifier
56
71
  end
57
72
  end
58
73
 
74
+ context '.registered?' do
75
+ it 'should return true when registered' do
76
+ expect(Hydra::RemoteIdentifier.registered?(:doi, target)).to eq(true)
77
+ end
78
+
79
+ it 'should yield true when registered' do
80
+ expect { |b| Hydra::RemoteIdentifier.registered?(:doi, target, &b) }.to yield_control
81
+ end
82
+
83
+ it 'should yield a remote_service with one arg on the block' do
84
+ Hydra::RemoteIdentifier.registered?(:doi, target) do |arg1|
85
+ @arg1 = arg1
86
+ end
87
+ expect(@arg1).to be_instance_of(RemoteServices::Doi)
88
+ end
89
+
90
+ it 'should yield a remote_service and minting coordinator with two args' do
91
+ Hydra::RemoteIdentifier.registered?(:doi, target) do |arg1, arg2|
92
+ @arg1 = arg1
93
+ @arg2 = arg2
94
+ end
95
+ expect(@arg1).to be_instance_of(RemoteServices::Doi)
96
+ expect(@arg2).to be_instance_of(MintingCoordinator)
97
+ end
98
+
99
+ it 'should return false when not registered' do
100
+ expect(Hydra::RemoteIdentifier.registered?(:doi, double)).to eq(false)
101
+ end
102
+
103
+ it 'should return false when service does not exist' do
104
+ expect(Hydra::RemoteIdentifier.registered?(:alternate, double)).to eq(false)
105
+ end
106
+
107
+ end
108
+
59
109
  context '.remote_uri_for' do
60
110
  it {
61
111
  expect(Hydra::RemoteIdentifier.remote_uri_for(:doi, expected_doi)).
@@ -93,8 +143,8 @@ module Hydra::RemoteIdentifier
93
143
  }.to change(target, :set_identifier).from(nil).to(expected_doi)
94
144
  end
95
145
 
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)
146
+ it 'returns true minting occurred', VCR::SpecSupport(record: :new_episodes, cassette_name: 'doi-integration') do
147
+ expect(Hydra::RemoteIdentifier.mint(:doi, target)).to eq(true)
98
148
  end
99
149
 
100
150
  it 'returns false if the target is not configured for identifiers' do
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.5.3
4
+ version: 0.6.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-10 00:00:00.000000000 Z
11
+ date: 2013-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport