yaks 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yaks/mapper/link.rb +6 -2
- data/lib/yaks/resource/link.rb +4 -0
- data/lib/yaks/version.rb +1 -1
- data/lib/yaks.rb +2 -2
- data/spec/unit/yaks/mapper/link_spec.rb +13 -0
- 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: 45ba297e354c237fe7dac7c3570c9405b1235c03
|
4
|
+
data.tar.gz: b8d1873f4e2bb1b4103608a48660a13a970babf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44d29bbb7d61bb15939d6b8d14ee7267d95c6c52003fdd560d3046a7484d344b3e1c7b0fb0ba4bb220bb06475b78305033506e9192da7c4f3df0f74a7665e654
|
7
|
+
data.tar.gz: 9b5c263fa66d6c519087164de7b1c0d6d626dc99b221efcc83ca103361e983b474e1116472ebc5af620fb7471d2d294a892754f775948a9549e0ebbaafe55a19
|
data/lib/yaks/mapper/link.rb
CHANGED
@@ -35,7 +35,11 @@ module Yaks
|
|
35
35
|
def add_to_resource(resource, mapper, _context)
|
36
36
|
resource_link = map_to_resource_link(mapper)
|
37
37
|
return resource unless resource_link
|
38
|
-
|
38
|
+
if options[:replace]
|
39
|
+
resource.links(resource.links.reject {|link| link.rel?(rel)} << resource_link)
|
40
|
+
else
|
41
|
+
resource.add_link(resource_link)
|
42
|
+
end
|
39
43
|
end
|
40
44
|
|
41
45
|
def rel?(rel)
|
@@ -62,7 +66,7 @@ module Yaks
|
|
62
66
|
options = options()
|
63
67
|
options = options.merge(title: Resolve(options[:title], mapper)) if options.key?(:title)
|
64
68
|
options = options.merge(templated: true) if templated?
|
65
|
-
options.reject{|key|
|
69
|
+
options.reject{|key| [:expand, :replace].include? key }
|
66
70
|
end
|
67
71
|
|
68
72
|
end
|
data/lib/yaks/resource/link.rb
CHANGED
data/lib/yaks/version.rb
CHANGED
data/lib/yaks.rb
CHANGED
@@ -44,6 +44,19 @@ RSpec.describe Yaks::Mapper::Link do
|
|
44
44
|
)
|
45
45
|
end
|
46
46
|
end
|
47
|
+
|
48
|
+
context 'with :replace => true' do
|
49
|
+
let(:options) { { replace: true } }
|
50
|
+
let(:resource) {
|
51
|
+
Yaks::Resource.new.add_link(Yaks::Resource::Link.new(rel: :next, uri: '/api/next'))
|
52
|
+
}
|
53
|
+
|
54
|
+
it 'should replace earlier links of the same rel' do
|
55
|
+
expect(link.add_to_resource(resource, mapper, yaks_context)).to eql(
|
56
|
+
Yaks::Resource.new(links: [Yaks::Resource::Link.new(rel: :next, uri: "/foo/bar/3/4")])
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
47
60
|
end
|
48
61
|
|
49
62
|
describe '#rel?' do
|