hydra-remote_identifier 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hydra/remote_identifier/exceptions.rb +7 -0
- data/lib/hydra/remote_identifier/mapper.rb +9 -5
- data/lib/hydra/remote_identifier/minter.rb +3 -0
- data/lib/hydra/remote_identifier/minting_coordinator.rb +4 -17
- data/lib/hydra/remote_identifier/registration.rb +3 -29
- data/lib/hydra/remote_identifier/remote_service.rb +5 -0
- data/lib/hydra/remote_identifier/version.rb +1 -1
- data/spec/lib/hydra/remote_identifier/minting_coordinator_spec.rb +3 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c212f0c8fbb12faf3510a14674d470e79475cc28
|
4
|
+
data.tar.gz: 28b81cd39c16f2c191c79ce226bfc7f333718c82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef7b1d1f3f40c22b6169a456814ae2dce2925a1f66fba6fb51a7ae0ad92891a8ad3cb212db376312420ea9209b34663210a6f224d2041d1a07df2cd8e944b4c0
|
7
|
+
data.tar.gz: 38c365ad04bea7a1452900aea09090441bb309757254b5024a223533302ce473766911be6d41e15e7ec07a012768f4095ed4dcdc496172618c1abc1c7b925490
|
@@ -1,11 +1,12 @@
|
|
1
|
+
require File.expand_path('../exceptions', __FILE__)
|
2
|
+
|
1
3
|
module Hydra::RemoteIdentifier
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
6
|
-
end
|
4
|
+
|
5
|
+
# Registry is responsible for associating a model with a set of remote services and defining the attribute map
|
6
|
+
# The Mapper is responsible for transforming a target, via a Map, into an acceptable format for a Minter
|
7
7
|
class Mapper
|
8
8
|
|
9
|
+
# The Wrapper provides the getting and setting behavior for a target based on a Map
|
9
10
|
class Wrapper
|
10
11
|
attr_reader :map, :target
|
11
12
|
def initialize(map, target)
|
@@ -50,6 +51,9 @@ module Hydra::RemoteIdentifier
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
54
|
+
# The Map is responsible for defining which attributes on the target map
|
55
|
+
# to the attributes expected in the RemoteService as well as defining
|
56
|
+
# how the RemoteService can update the target
|
53
57
|
class Map < BasicObject
|
54
58
|
attr_reader :service_class, :_getters, :_setter
|
55
59
|
def initialize(service_class, &config)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Hydra::RemoteIdentifier
|
2
2
|
|
3
|
+
# The Minting
|
3
4
|
class MintingCoordinator
|
4
|
-
attr_reader :service_class, :
|
5
|
-
def initialize(service_class,
|
5
|
+
attr_reader :service_class, :mapper
|
6
|
+
def initialize(service_class, mapper_builder = Mapper, &map_config)
|
6
7
|
@service_class = service_class
|
7
|
-
@target_class = target_class
|
8
8
|
@mapper = mapper_builder.new(service_class, &map_config)
|
9
9
|
end
|
10
10
|
|
@@ -21,17 +21,4 @@ module Hydra::RemoteIdentifier
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
let(:service_class) { Class.new { def self.valid_attribute?(*); true; end } }
|
26
|
-
let(:target_class) { Class.new }
|
27
|
-
let(:mapper_builder) { double(new: double(call: :wrapped_target)) }
|
28
|
-
let(:target) { target_class.new }
|
29
|
-
let(:map) { lambda {|*|} }
|
30
|
-
subject { MintingCoordinator.new(service_class, target_class, mapper_builder, &map) }
|
31
|
-
it 'forward delegates call to the minter' do
|
32
|
-
minter = double
|
33
|
-
minter.should_receive(:call).with(kind_of(service_class), :wrapped_target)
|
34
|
-
subject.call(target, minter)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
24
|
+
end
|
@@ -2,6 +2,8 @@ require 'active_support/core_ext/class/attribute'
|
|
2
2
|
|
3
3
|
module Hydra::RemoteIdentifier
|
4
4
|
|
5
|
+
# The Registration is responsible for connecting a RemoteService, a Target
|
6
|
+
# to a particular Map
|
5
7
|
class Registration
|
6
8
|
def initialize(service_class, target_class, minting_coordinator = MintingCoordinator, &map)
|
7
9
|
if map.nil?
|
@@ -9,36 +11,8 @@ module Hydra::RemoteIdentifier
|
|
9
11
|
end
|
10
12
|
target_class.class_attribute :registered_remote_identifier_minters unless target_class.respond_to?(:registered_remote_identifier_minters)
|
11
13
|
target_class.registered_remote_identifier_minters ||= []
|
12
|
-
target_class.registered_remote_identifier_minters += [minting_coordinator.new(service_class,
|
14
|
+
target_class.registered_remote_identifier_minters += [minting_coordinator.new(service_class, &map)]
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
describe Registration do
|
17
|
-
|
18
|
-
let(:minting_coordinator) { double(new: :minting_coordinator) }
|
19
|
-
let(:remote_service) { RemoteService }
|
20
|
-
let(:target_class) { Class.new }
|
21
|
-
let(:map) { lambda {|m| m.title :title } }
|
22
|
-
|
23
|
-
it 'requires a map' do
|
24
|
-
expect { Registration.new(remote_service, target_class, minting_coordinator) }.to raise_error(RuntimeError)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'adds a .registered_remote_identifier_minters method' do
|
28
|
-
expect {
|
29
|
-
Registration.new(remote_service, target_class, minting_coordinator, &map)
|
30
|
-
}.to change{ target_class.respond_to?(:registered_remote_identifier_minters) }.from(false).to(true)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'adds a .registered_remote_identifier_minters method' do
|
34
|
-
Registration.new(remote_service, target_class, minting_coordinator, &map)
|
35
|
-
expect(target_class.registered_remote_identifier_minters).to eq [:minting_coordinator]
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should yield a map' do
|
39
|
-
Registration.new(remote_service, target_class, minting_coordinator, &map)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
18
|
end
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module Hydra::RemoteIdentifier
|
2
2
|
|
3
|
+
# The RemoteService is responsible for delivering a payload to a remote
|
4
|
+
# identification minting service and returning an identifier.
|
5
|
+
#
|
6
|
+
# It is responsible for assisting the construction and validation of a remote
|
7
|
+
# payload.
|
3
8
|
class RemoteService
|
4
9
|
|
5
10
|
def self.valid_attribute?(attribute_name)
|
@@ -3,15 +3,14 @@ require File.expand_path('../../../../../lib/hydra/remote_identifier/minting_coo
|
|
3
3
|
module Hydra::RemoteIdentifier
|
4
4
|
describe MintingCoordinator do
|
5
5
|
let(:service_class) { Class.new { def self.valid_attribute?(*); true; end } }
|
6
|
-
let(:target_class) { Class.new }
|
7
6
|
let(:mapper_builder) { double(new: double(call: :wrapped_target)) }
|
8
|
-
let(:target) {
|
7
|
+
let(:target) { double }
|
9
8
|
let(:map) { lambda {|*|} }
|
10
|
-
subject { MintingCoordinator.new(service_class,
|
9
|
+
subject { MintingCoordinator.new(service_class, mapper_builder, &map) }
|
11
10
|
it 'forward delegates call to the minter' do
|
12
11
|
minter = double
|
13
12
|
minter.should_receive(:call).with(kind_of(service_class), :wrapped_target)
|
14
13
|
subject.call(target, minter)
|
15
14
|
end
|
16
15
|
end
|
17
|
-
end
|
16
|
+
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Friesen
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- Rakefile
|
89
89
|
- hydra-remote_identifier.gemspec
|
90
90
|
- lib/hydra/remote_identifier.rb
|
91
|
+
- lib/hydra/remote_identifier/exceptions.rb
|
91
92
|
- lib/hydra/remote_identifier/mapper.rb
|
92
93
|
- lib/hydra/remote_identifier/minter.rb
|
93
94
|
- lib/hydra/remote_identifier/minting_coordinator.rb
|