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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 776238668b4fdadb94093d0238f2c70410839554
4
- data.tar.gz: 9f0a6759d926591facf1e6e1e76ea8f74502744b
3
+ metadata.gz: 45ba297e354c237fe7dac7c3570c9405b1235c03
4
+ data.tar.gz: b8d1873f4e2bb1b4103608a48660a13a970babf0
5
5
  SHA512:
6
- metadata.gz: 27ab2fc145cc3e3cbc64f9cc78bc941268a41858f1ccac9d3a45735b1f779299edb91aa2d9f7ae07f31ab81b4d74b549113477bbcc8468c2f8300b62d9179346
7
- data.tar.gz: cec0a45406bdfbfa0906ba696d21753e25797360a6505eca8ba1b7b773dd5591fc2e18e7fbe0085c941677f5d833a64bc14d4b262130d635606daa763a705249
6
+ metadata.gz: 44d29bbb7d61bb15939d6b8d14ee7267d95c6c52003fdd560d3046a7484d344b3e1c7b0fb0ba4bb220bb06475b78305033506e9192da7c4f3df0f74a7665e654
7
+ data.tar.gz: 9b5c263fa66d6c519087164de7b1c0d6d626dc99b221efcc83ca103361e983b474e1116472ebc5af620fb7471d2d294a892754f775948a9549e0ebbaafe55a19
@@ -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
- resource.add_link(resource_link)
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| key.equal? :expand }
69
+ options.reject{|key| [:expand, :replace].include? key }
66
70
  end
67
71
 
68
72
  end
@@ -10,6 +10,10 @@ module Yaks
10
10
  def templated?
11
11
  options.fetch(:templated) { false }
12
12
  end
13
+
14
+ def rel?(rel)
15
+ rel().eql? rel
16
+ end
13
17
  end
14
18
  end
15
19
  end
data/lib/yaks/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yaks
2
- VERSION = '0.7.4'
2
+ VERSION = '0.7.5'
3
3
  end
data/lib/yaks.rb CHANGED
@@ -23,8 +23,8 @@ require 'yaks/errors'
23
23
  require 'yaks/default_policy'
24
24
 
25
25
  module Yaks
26
- # A PORO
27
- Undefined = Object.new
26
+ Undefined = Module.new.freeze
27
+
28
28
  # Set the Root constant as the gems root path
29
29
  Root = Pathname(__FILE__).join('../..')
30
30
 
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arne Brasseur