lhs 16.1.0 → 16.1.1

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: 40c9a3c78d7e3f84b0652f9903eaba8b6f7312a7bd1b0e1a2f59100a6f296acb
4
- data.tar.gz: a70e74d0de431175fe821751884d6b4eb60cc7e9bdd8c1237e906e41723c6b97
3
+ metadata.gz: 040a79027ac392157392edd52aa521fb295de1e5a7dc9e6450c08c55bb0998a2
4
+ data.tar.gz: 9689bd2cd92b51ce3c74072077a8219a8c844514c2efcda4d119f43f621b98fc
5
5
  SHA512:
6
- metadata.gz: 8b5952d6ef6362ac7f9689a6c845469af65d8047228b267af4c28828adafdc776458af6a6562f395ae4dcc622b8462ef30f6b6e9c62a105a35ba9eb02f3d2b27
7
- data.tar.gz: c554b8122c917cab6866bed3c081cebfc66d35971c10a085617fc0eec546d9e1e2542c7cfeae93400c1a07e4402398750317fcbd270f9b3d09a9bfe16f3eb9fe
6
+ metadata.gz: b1a9e030f8741fe429bc56f43e48d9b694c1d7b7c3e296c7ec4b9d6cfdd3b123828dd115e9ac3371dc1ed0d01fc82cd029330422e8418d89053f9160c0fa8be4
7
+ data.tar.gz: 7503c74fe4756bb2086334253d06939f1ebc9a0b4cbfdadae460229c2ccc2243cba2acbf01c74593aaef0d81bcfc35937258ff360e05c9cf9262e9ba70861a03
@@ -77,7 +77,10 @@ class LHS::Proxy
77
77
  data.errors = LHS::Problems::Nested::Errors.new(errors, name) if errors.any?
78
78
  data.warnings = LHS::Problems::Nested::Warnings.new(warnings, name) if warnings.any?
79
79
  return data.becomes(record) if record && !value.is_a?(LHS::Record)
80
- return data.becomes(_record._relations[name][:record_class_name].constantize) if _record && _record._relations[name]
80
+ if _record && _record._relations[name]
81
+ klass = _record._relations[name][:record_class_name].constantize
82
+ return cache.compute_if_absent(klass) { data.becomes(klass) }
83
+ end
81
84
  data
82
85
  end
83
86
 
@@ -104,5 +107,9 @@ class LHS::Proxy
104
107
  def date_time_regex
105
108
  /(?<date>\d{4}-\d{2}-\d{2})?(?<time>T\d{2}:\d{2}(:\d{2}(\.\d*.\d{2}:\d{2})*)?)?/
106
109
  end
110
+
111
+ def cache
112
+ @cache ||= Concurrent::Map.new
113
+ end
107
114
  end
108
115
  end
data/lib/lhs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '16.1.0'
2
+ VERSION = '16.1.1'
3
3
  end
@@ -6,12 +6,14 @@ describe LHS::Record do
6
6
  let(:user) { transaction.user }
7
7
 
8
8
  before do
9
- stub_request(:get, 'http://myservice/transactions/1')
10
- .to_return(body: {
11
- user: {
12
- email_address: 'steve@local.ch'
13
- }
14
- }.to_json)
9
+ [1, 2].each do |id|
10
+ stub_request(:get, "http://myservice/transactions/#{id}")
11
+ .to_return(body: {
12
+ user: {
13
+ email_address: 'steve@local.ch'
14
+ }
15
+ }.to_json)
16
+ end
15
17
  end
16
18
 
17
19
  context 'has_one' do
@@ -40,6 +42,13 @@ describe LHS::Record do
40
42
  expect(user._root._raw).to eq transaction._raw
41
43
  expect(user.parent._raw).to eq transaction._raw
42
44
  end
45
+
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)
49
+ transaction2 = Transaction.find(2)
50
+ expect(transaction2.user.object_id).not_to eql(object_id)
51
+ end
43
52
  end
44
53
 
45
54
  context 'custom class_name' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.1.0
4
+ version: 16.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-06 00:00:00.000000000 Z
11
+ date: 2018-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel