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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ddccef7b4b1d4c0bf21e0afe5596f375b79ae40
4
- data.tar.gz: f979c71a8daa29d9e291e6c2c06d4c3abd7c9223
3
+ metadata.gz: e6671569000710d40972edffeba71ed8d9630ffb
4
+ data.tar.gz: cc5fc8ac334267db1c39cc7163bf7bd61d658084
5
5
  SHA512:
6
- metadata.gz: 8fef1c7a9b0b4bc6739d003278978791705661bec3dd8722cdbfa1e8c34f8f0b01700fa1bc39da55dc71258a3d82b2ddc74ee1c030b197651809af67b619cd79
7
- data.tar.gz: 117fcc9c8a4236d629d2517a77c6b61ee84f004064d4d0c6abd1df77160faa2eb51ad8902c7d2a19c02ddc8f85bfd9cdcafb9d446ddb9b6bc70c4055363063d7
6
+ metadata.gz: 2ef1d42b975f4120a5bef5966e68e8ea2a5c47daf44fe5b472c002a24e7004a3ba83162d2d0ba73ee9cb2fcfeb39254c39c60f107cb8fd8f028b34d8cc88b27a
7
+ data.tar.gz: 55ed68f8a5cf38a928c88c7b8aee56b18485d5fa895031904471eca64bd52ab4c0cabcd0c875d07fc5982e1823a7bd2f3d1c3b489f6e7b7cd549d4764206ee6c
@@ -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
- FedoraLens.id_to_uri(id)
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.uri_to_id(uri)
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)
@@ -47,14 +47,15 @@ module FedoraLens
47
47
  ]
48
48
  end
49
49
 
50
- def uris_to_ids
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| FedoraLens.uri_to_id(URI.parse(uri).to_s) }
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(FedoraLens.id_to_uri(value))
58
+ RDF::URI.new(yield.id_to_uri(value))
58
59
  end
59
60
  end
60
61
  ]
@@ -1,3 +1,3 @@
1
1
  module FedoraLens
2
- VERSION = '0.0.12'
2
+ VERSION = '0.0.13'
3
3
  end
@@ -57,17 +57,26 @@ module FedoraLens
57
57
  end
58
58
 
59
59
  describe ".uris_to_ids" do
60
- let(:lens) { Lenses.uris_to_ids }
60
+ let(:mapper) { double('mapper') }
61
+ let(:lens) { Lenses.uris_to_ids { mapper } }
61
62
 
62
- let(:original) { [RDF::URI.new(FedoraLens.host + '/id/123'), RDF::URI.new(FedoraLens.host + '/id/321')] }
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) { original }
75
+ let(:input) { uris }
69
76
  it "casts them to string" do
70
- expect(subject).to eq ['/id/123', '/id/321']
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(:input) { ['/id/777', '/id/888'] }
96
+ let(:id1) { '/id/777' }
97
+ let(:id2) { '/id/888' }
98
+ let(:input) { ids }
87
99
  it "overwrites the items" do
88
- expect(subject).to eq [RDF::URI.new(FedoraLens.host + '/id/777'), RDF::URI.new(FedoraLens.host + '/id/888')]
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
 
@@ -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 '/41/0d/6b/47/410d6b47-ce9c-4fa0-91e2-d62765667c52'
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 '/test' }
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 '/test/foo' }
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 '/foo' }
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 '/foo/bar' }
175
+ it { should eq 'foo/bar' }
176
176
  end
177
177
  end
178
178
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedora_lens
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne