fedora_lens 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fedora_lens/core.rb +5 -11
- data/lib/fedora_lens/lenses.rb +4 -3
- data/lib/fedora_lens/version.rb +1 -1
- data/spec/fedora_lens/lenses_spec.rb +20 -6
- data/spec/fedora_lens_spec.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6671569000710d40972edffeba71ed8d9630ffb
|
4
|
+
data.tar.gz: cc5fc8ac334267db1c39cc7163bf7bd61d658084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ef1d42b975f4120a5bef5966e68e8ea2a5c47daf44fe5b472c002a24e7004a3ba83162d2d0ba73ee9cb2fcfeb39254c39c60f107cb8fd8f028b34d8cc88b27a
|
7
|
+
data.tar.gz: 55ed68f8a5cf38a928c88c7b8aee56b18485d5fa895031904471eca64bd52ab4c0cabcd0c875d07fc5982e1823a7bd2f3d1c3b489f6e7b7cd549d4764206ee6c
|
data/lib/fedora_lens/core.rb
CHANGED
@@ -43,15 +43,6 @@ module FedoraLens
|
|
43
43
|
@@base_path = path
|
44
44
|
end
|
45
45
|
|
46
|
-
def id_to_uri(id)
|
47
|
-
id = "/#{id}" unless id.start_with? '/'
|
48
|
-
id = FedoraLens.base_path + id unless id.start_with? "#{FedoraLens.base_path}/"
|
49
|
-
FedoraLens.host + id
|
50
|
-
end
|
51
|
-
|
52
|
-
def uri_to_id(uri)
|
53
|
-
uri.to_s.sub(FedoraLens.host + FedoraLens.base_path, '')
|
54
|
-
end
|
55
46
|
end
|
56
47
|
|
57
48
|
module Core
|
@@ -185,11 +176,14 @@ module FedoraLens
|
|
185
176
|
end
|
186
177
|
|
187
178
|
def id_to_uri(id)
|
188
|
-
|
179
|
+
id = "/#{id}" unless id.start_with? '/'
|
180
|
+
id = FedoraLens.base_path + id unless id.start_with? "#{FedoraLens.base_path}/"
|
181
|
+
FedoraLens.host + id
|
189
182
|
end
|
190
183
|
|
191
184
|
def uri_to_id(uri)
|
192
|
-
FedoraLens.
|
185
|
+
id = uri.to_s.sub(FedoraLens.host + FedoraLens.base_path, '')
|
186
|
+
id.start_with?('/') ? id[1..-1] : id
|
193
187
|
end
|
194
188
|
|
195
189
|
def create(data)
|
data/lib/fedora_lens/lenses.rb
CHANGED
@@ -47,14 +47,15 @@ module FedoraLens
|
|
47
47
|
]
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
# @param class_lambda [Proc] returns an object which implements uri_to_id and id_to_uri
|
51
|
+
def uris_to_ids(&block)
|
51
52
|
Lens[
|
52
53
|
get: lambda do |source|
|
53
|
-
source.map { |uri|
|
54
|
+
source.map { |uri| yield.uri_to_id(URI.parse(uri).to_s) }
|
54
55
|
end,
|
55
56
|
put: lambda do |sources, values|
|
56
57
|
Array(values).compact.map do |value|
|
57
|
-
RDF::URI.new(
|
58
|
+
RDF::URI.new(yield.id_to_uri(value))
|
58
59
|
end
|
59
60
|
end
|
60
61
|
]
|
data/lib/fedora_lens/version.rb
CHANGED
@@ -57,17 +57,26 @@ module FedoraLens
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe ".uris_to_ids" do
|
60
|
-
let(:
|
60
|
+
let(:mapper) { double('mapper') }
|
61
|
+
let(:lens) { Lenses.uris_to_ids { mapper } }
|
61
62
|
|
62
|
-
let(:
|
63
|
+
let(:id1) { '/id/123' }
|
64
|
+
let(:id2) { '/id/321' }
|
65
|
+
let(:uri1) { RDF::URI.new(FedoraLens.host + id1) }
|
66
|
+
let(:uri2) { RDF::URI.new(FedoraLens.host + id2) }
|
67
|
+
|
68
|
+
let(:ids) { [id1, id2] }
|
69
|
+
let(:uris) { [uri1, uri2] }
|
63
70
|
|
64
71
|
describe "#get" do
|
65
72
|
subject { lens.get(input) }
|
66
73
|
|
67
74
|
context "with exiting content" do
|
68
|
-
let(:input) {
|
75
|
+
let(:input) { uris }
|
69
76
|
it "casts them to string" do
|
70
|
-
expect(
|
77
|
+
expect(mapper).to receive(:uri_to_id).with(uri1).and_return(id1)
|
78
|
+
expect(mapper).to receive(:uri_to_id).with(uri2).and_return(id2)
|
79
|
+
expect(subject).to eq ids
|
71
80
|
end
|
72
81
|
end
|
73
82
|
|
@@ -80,12 +89,17 @@ module FedoraLens
|
|
80
89
|
end
|
81
90
|
|
82
91
|
describe "#put" do
|
92
|
+
let(:original) { [RDF::URI.new(FedoraLens.host + '/foo/1'), RDF::URI.new(FedoraLens.host + '/foo/2')] }
|
83
93
|
subject { lens.put(original, input) }
|
84
94
|
|
85
95
|
context "with new values " do
|
86
|
-
let(:
|
96
|
+
let(:id1) { '/id/777' }
|
97
|
+
let(:id2) { '/id/888' }
|
98
|
+
let(:input) { ids }
|
87
99
|
it "overwrites the items" do
|
88
|
-
expect(
|
100
|
+
expect(mapper).to receive(:id_to_uri).with(id1).and_return(uri1)
|
101
|
+
expect(mapper).to receive(:id_to_uri).with(id2).and_return(uri2)
|
102
|
+
expect(subject).to eq uris
|
89
103
|
end
|
90
104
|
end
|
91
105
|
|
data/spec/fedora_lens_spec.rb
CHANGED
@@ -73,7 +73,7 @@ describe FedoraLens do
|
|
73
73
|
describe "#id" do
|
74
74
|
it "should not have 'fedora' in the id" do
|
75
75
|
m = TestClass.new(FedoraLens.host + '/41/0d/6b/47/410d6b47-ce9c-4fa0-91e2-d62765667c52')
|
76
|
-
expect(m.id).to eq '
|
76
|
+
expect(m.id).to eq '41/0d/6b/47/410d6b47-ce9c-4fa0-91e2-d62765667c52'
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -150,11 +150,11 @@ describe FedoraLens do
|
|
150
150
|
|
151
151
|
context "at the base level" do
|
152
152
|
let(:uri) { "#{FedoraLens.host}/test" }
|
153
|
-
it { should eq '
|
153
|
+
it { should eq 'test' }
|
154
154
|
end
|
155
155
|
context "at the second level" do
|
156
156
|
let(:uri) { "#{FedoraLens.host}/test/foo" }
|
157
|
-
it { should eq '
|
157
|
+
it { should eq 'test/foo' }
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -168,11 +168,11 @@ describe FedoraLens do
|
|
168
168
|
|
169
169
|
context "at the base level" do
|
170
170
|
let(:uri) { "#{FedoraLens.host}/test/foo" }
|
171
|
-
it { should eq '
|
171
|
+
it { should eq 'foo' }
|
172
172
|
end
|
173
173
|
context "at the second level" do
|
174
174
|
let(:uri) { "#{FedoraLens.host}/test/foo/bar" }
|
175
|
-
it { should eq '
|
175
|
+
it { should eq 'foo/bar' }
|
176
176
|
end
|
177
177
|
end
|
178
178
|
end
|