ree_lib 1.0.50 → 1.0.51

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
  SHA256:
3
- metadata.gz: 4a53010ba7fdd43f86e011e0ee3f90675bb71e1b7f0c66d127736918ec89f6f0
4
- data.tar.gz: 739eeb996f5ebfff231c613b5a6fd13022a4e91c5fa05716902dbd37d32f4d26
3
+ metadata.gz: 11c4d5cf16a6bfdbea763761f5f4a1c993d15b0fe5e912e257df949d5d6a9fd2
4
+ data.tar.gz: 1254d959c594b4b5cbf71c13c04304910648e937ca946c37bfe21dfb32593463
5
5
  SHA512:
6
- metadata.gz: f3a66d7108179a12e92fc5b36eb1adaaff37a733760f02e8867bcd949b9507b966161c4cb245da9d308de3d6066d8e6990ebd81b7a0d76a3e52e6fca02b75fd3
7
- data.tar.gz: 5008628b066547548f69f3690d14e3103756b01573d3be8eb001450538c76a88c4adf3ebfec0ae36b5b47c13af9f598264d11a50c3a54f8eca0f3a630039563c
6
+ metadata.gz: 36d76d580636a9990a1a691685931e987eb3f9e6cb0ca9f5bcc8759f4bdb1a6c542bcc24768272abec7c7c84f0828508904d49cc988b92fcf9337207259f4e78
7
+ data.tar.gz: 752394c6296ae13cfb4a8d963b0aeaff3de295863c5c48271001c2227a509b371bc264bd1a0942bf2de59b9786f5620ce2053f8e2518e721180c7f27c81ced23
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.50)
4
+ ree_lib (1.0.51)
5
5
  binding_of_caller (~> 1.0.0)
6
6
  i18n (~> 1.12.0)
7
7
  loofah (~> 2.18.0)
@@ -38,12 +38,14 @@ GEM
38
38
  crass (~> 1.0.2)
39
39
  nokogiri (>= 1.5.9)
40
40
  msgpack (1.6.0)
41
+ nokogiri (1.15.2-x86_64-darwin)
42
+ racc (~> 1.4)
41
43
  nokogiri (1.15.2-x86_64-linux)
42
44
  racc (~> 1.4)
43
45
  oj (3.13.23)
44
46
  pg (1.4.6)
45
47
  public_suffix (5.0.1)
46
- racc (1.6.2)
48
+ racc (1.7.1)
47
49
  rack (3.0.5)
48
50
  rack-test (2.0.2)
49
51
  rack (>= 1.3)
@@ -105,12 +105,12 @@ module ReeDao
105
105
  )
106
106
  def association(assoc_type, assoc_name, **assoc_opts, &block)
107
107
  if self.class.sync_mode?
108
- return if association_is_not_included?(assoc_name)
108
+ return if association_is_not_included?(assoc_name) || list.empty?
109
109
 
110
110
  association = Association.new(self, list, **global_opts)
111
111
  association.load(assoc_type, assoc_name, **assoc_opts, &block)
112
112
  else
113
- return @threads if association_is_not_included?(assoc_name)
113
+ return @threads if association_is_not_included?(assoc_name) || list.empty?
114
114
 
115
115
  @threads << Thread.new do
116
116
  association = Association.new(self, list, **global_opts)
@@ -47,6 +47,8 @@ class ReeDao::LoadAgg
47
47
  private
48
48
 
49
49
  def load_associations(list, **opts, &block)
50
+ return if list.empty?
51
+
50
52
  local_vars = block.binding.eval(<<-CODE, __FILE__, __LINE__ + 1)
51
53
  vars = self.instance_variables
52
54
  vars.reduce({}) { |hsh, var| hsh[var] = self.instance_variable_get(var); hsh }
@@ -54,10 +56,12 @@ class ReeDao::LoadAgg
54
56
 
55
57
  agg_caller = block.binding.eval("self")
56
58
 
59
+ associations = Associations.new(agg_caller, list, local_vars, **opts).instance_exec(list, &block)
60
+
57
61
  if ReeDao.load_sync_associations_enabled?
58
- Associations.new(agg_caller, list, local_vars, **opts).instance_exec(list, &block)
62
+ associations
59
63
  else
60
- Associations.new(agg_caller, list, local_vars, **opts).instance_exec(list, &block).map(&:join)
64
+ associations.map(&:join)
61
65
  end
62
66
  end
63
67
  end
@@ -203,7 +203,8 @@ RSpec.describe :load_agg do
203
203
  end
204
204
 
205
205
  def call(ids_or_scope, **opts)
206
- load_agg(ids_or_scope, users, **opts) do
206
+ load_agg(ids_or_scope, users, **opts) do |agg_list|
207
+ some_id = agg_list.first.id
207
208
  title = "1984"
208
209
  belongs_to :organization
209
210
 
@@ -348,6 +349,30 @@ RSpec.describe :load_agg do
348
349
  expect(res_user.books.count).to eq(1)
349
350
  }
350
351
 
352
+ it {
353
+ organizations.delete_all
354
+ users.delete_all
355
+ books.delete_all
356
+
357
+ organization = ReeDaoLoadAggTest::Organization.new(name: "Test Org")
358
+ organizations.put(organization)
359
+
360
+ user_1 = ReeDaoLoadAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
361
+ user_2 = ReeDaoLoadAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
362
+ users.put(user_1)
363
+ users.put(user_2)
364
+
365
+ book_1 = ReeDaoLoadAggTest::Book.new(user_id: user_1.id, title: "1984")
366
+ book_2 = ReeDaoLoadAggTest::Book.new(user_id: user_1.id, title: "1408")
367
+
368
+ books.put(book_1)
369
+ books.put(book_2)
370
+
371
+ expect {
372
+ users_agg_scope_method.call(users.where(name: "Another names"))
373
+ }.to_not raise_error
374
+ }
375
+
351
376
  it {
352
377
  organizations.delete_all
353
378
  users.delete_all
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.50"
4
+ VERSION = "1.0.51"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.50
4
+ version: 1.0.51
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov