lhs 16.1.1 → 16.1.2

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
  SHA256:
3
- metadata.gz: 040a79027ac392157392edd52aa521fb295de1e5a7dc9e6450c08c55bb0998a2
4
- data.tar.gz: 9689bd2cd92b51ce3c74072077a8219a8c844514c2efcda4d119f43f621b98fc
3
+ metadata.gz: 07100d466b8e07fda10f73bf8b76c45eee3caf8d187221e919e8ea9fb32a795e
4
+ data.tar.gz: 92aa74f46a7f46df4d76c18b3ae9c6b57cc1aae8d6c55ae14c793acad5cd086a
5
5
  SHA512:
6
- metadata.gz: b1a9e030f8741fe429bc56f43e48d9b694c1d7b7c3e296c7ec4b9d6cfdd3b123828dd115e9ac3371dc1ed0d01fc82cd029330422e8418d89053f9160c0fa8be4
7
- data.tar.gz: 7503c74fe4756bb2086334253d06939f1ebc9a0b4cbfdadae460229c2ccc2243cba2acbf01c74593aaef0d81bcfc35937258ff360e05c9cf9262e9ba70861a03
6
+ metadata.gz: f31cbc7ea4f1b72c49aa5953a66857b0d8128ed7b6a521d3b61fe1f7eceb8f11c13e0a31bb69a069ab8db1fc758f6c9d367250bcecb09324c8899e331aed580d
7
+ data.tar.gz: 15be398c376a80e30ada0f68ad3be7bc1265525eeec7a911046b41c34aaf17f759299492574774f2c393132dae392b4a29b21ce73f81cbadf9aafd98444c21b3
@@ -13,6 +13,7 @@ class LHS::Proxy
13
13
  private
14
14
 
15
15
  def set(name, value)
16
+ clear_cache!
16
17
  key = name.to_s.gsub(/=$/, '')
17
18
  _data._raw[key.to_sym] = value
18
19
  end
@@ -76,10 +77,11 @@ class LHS::Proxy
76
77
  data = (value.is_a?(LHS::Data) || value.is_a?(LHS::Record)) ? value : LHS::Data.new(value, _data, _record, _request)
77
78
  data.errors = LHS::Problems::Nested::Errors.new(errors, name) if errors.any?
78
79
  data.warnings = LHS::Problems::Nested::Warnings.new(warnings, name) if warnings.any?
79
- return data.becomes(record) if record && !value.is_a?(LHS::Record)
80
80
  if _record && _record._relations[name]
81
81
  klass = _record._relations[name][:record_class_name].constantize
82
82
  return cache.compute_if_absent(klass) { data.becomes(klass) }
83
+ elsif record && !value.is_a?(LHS::Record)
84
+ return data.becomes(record)
83
85
  end
84
86
  data
85
87
  end
@@ -111,5 +113,9 @@ class LHS::Proxy
111
113
  def cache
112
114
  @cache ||= Concurrent::Map.new
113
115
  end
116
+
117
+ def clear_cache!
118
+ @cache = nil
119
+ end
114
120
  end
115
121
  end
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '16.1.1'
2
+ VERSION = '16.1.2'
3
3
  end
@@ -10,7 +10,8 @@ describe LHS::Record do
10
10
  stub_request(:get, "http://myservice/transactions/#{id}")
11
11
  .to_return(body: {
12
12
  user: {
13
- email_address: 'steve@local.ch'
13
+ email_address: 'steve@local.ch',
14
+ comments: []
14
15
  }
15
16
  }.to_json)
16
17
  end
@@ -26,11 +27,15 @@ describe LHS::Record do
26
27
  end
27
28
 
28
29
  class User < LHS::Record
30
+ has_many :comments
29
31
 
30
32
  def email
31
33
  self[:email_address]
32
34
  end
33
35
  end
36
+
37
+ class Comment < LHS::Record
38
+ end
34
39
  end
35
40
 
36
41
  it 'casts the relation into the correct type' do
@@ -43,11 +48,21 @@ describe LHS::Record do
43
48
  expect(user.parent._raw).to eq transaction._raw
44
49
  end
45
50
 
46
- it 'the relation is cached in memory' do
47
- object_id = transaction.user.object_id
48
- expect(transaction.user.object_id).to eql(object_id)
51
+ it 'caches the relation in memory' do
52
+ allow(LHS::Record).to receive(:for_url).and_return(User)
53
+ user_object_id = transaction.user.object_id
54
+ expect(transaction.user.object_id).to eql(user_object_id)
49
55
  transaction2 = Transaction.find(2)
50
- expect(transaction2.user.object_id).not_to eql(object_id)
56
+ expect(transaction2.user.object_id).not_to eql(user_object_id)
57
+ end
58
+
59
+ it 'recalculates cache for relation when it was modified' do
60
+ allow(LHS::Record).to receive(:for_url).and_return(Comment)
61
+ expect(user.comments).to be_blank
62
+ comments_object_id = user.comments.object_id
63
+ user.comments = [Comment.new]
64
+ expect(user.comments.object_id).not_to eql(comments_object_id)
65
+ expect(user.comments).not_to be_blank
51
66
  end
52
67
  end
53
68
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.1.1
4
+ version: 16.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors