ree_lib 1.0.56 → 1.0.57

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: 23c4603ab3ab820869ca4478b42b3d350c5484c8da7b21c99b469449f45764a1
4
- data.tar.gz: 4293f4d083185f09f6098e11698b5f35981a748b00ff84e486389bab19445751
3
+ metadata.gz: 84ad4225d13e31575c1799fd4c7a4b480a1e7ae6b9709834447a733a3a260367
4
+ data.tar.gz: ba98679b88ac6ad2cec30fcd0280c01638220fdd0a7488f8f33c7ead0dd2de7d
5
5
  SHA512:
6
- metadata.gz: fe885988996c1f0b9aeba40c9f61e119ab4ffc02aa471afe3774b470192fc5601093c1b13673febebad76bf348baa0be61cb2e19a5abf81b1970b518d86ddc9d
7
- data.tar.gz: acbdf84eacfa6c46c6997999af1e0eb5dc03eedc95b95d954927a3907048c9c28d924328041203d02db1bd5c9dc78310c2cc234db826c74e585a8701b7982ed9
6
+ metadata.gz: ccbda33bb5233fc869f470993a93ec1770471e6fdce354a49455bf15c487731b06384bb776ed762c172e75428d77a071fc4483087cdbd2de8ef780729ccae3ac
7
+ data.tar.gz: d24649974cf1ca2f05c0bece050a7aa91450244cc065f972acacef6f7d966ee52f285c458cf9925d76693b14862d9ebfe77d42142dbb1bea24c3277a26b5a887
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.56)
4
+ ree_lib (1.0.57)
5
5
  binding_of_caller (~> 1.0.0)
6
6
  i18n (~> 1.12.0)
7
7
  loofah (~> 2.18.0)
@@ -143,6 +143,8 @@ module ReeDao
143
143
  def get_assoc_opts(opts)
144
144
  if opts.is_a?(Proc)
145
145
  opts.call
146
+ elsif opts.is_a?(Sequel::Dataset)
147
+ { scope: opts }
146
148
  else
147
149
  {}
148
150
  end
@@ -37,7 +37,9 @@ class ReeDao::LoadAgg
37
37
  list = scope.is_a?(Sequel::Dataset) ? scope.all : scope
38
38
 
39
39
  if opts[:to_dto]
40
- list = opts[:to_dto].call(list)
40
+ list = list.map do |item|
41
+ list = opts[:to_dto].call(item)
42
+ end
41
43
  end
42
44
 
43
45
  load_associations(list, **opts, &block) if block_given?
@@ -275,7 +275,7 @@ RSpec.describe :load_agg do
275
275
  load_agg(users, ids_or_scope, **opts) do |agg_list|
276
276
  some_id = agg_list.first.id
277
277
  title = "1984"
278
- belongs_to :organization
278
+ belongs_to :organization, organizations.by_name("Corp")
279
279
 
280
280
  has_many :books, -> { books_opts(title) }
281
281
  end
@@ -292,6 +292,22 @@ RSpec.describe :load_agg do
292
292
  end
293
293
  end
294
294
 
295
+ class ReeDaoLoadAggTest::UsersAggOnlyDataset
296
+ include ReeDao::AggregateDSL
297
+
298
+ aggregate :users_agg_only_dataset do
299
+ link :users, from: :ree_dao_load_agg_test
300
+ link :books, from: :ree_dao_load_agg_test
301
+ link :load_agg, from: :ree_dao
302
+ end
303
+
304
+ def call(ids_or_scope, **opts)
305
+ load_agg(users, ids_or_scope, **opts) do
306
+ has_many :books, books.where(title: "1408")
307
+ end
308
+ end
309
+ end
310
+
295
311
  class ReeDaoLoadAggTest::UsersAggWithoutDao
296
312
  include ReeDao::AggregateDSL
297
313
 
@@ -316,6 +332,7 @@ RSpec.describe :load_agg do
316
332
  let(:users_agg_autoload_reviews_children) { ReeDaoLoadAggTest::UsersAggAutoloadReviewsChildren.new }
317
333
  let(:users_agg_without_dao) { ReeDaoLoadAggTest::UsersAggWithoutDao.new }
318
334
  let(:users_agg_with_dto) { ReeDaoLoadAggTest::UsersAggWithDto.new }
335
+ let(:users_agg_only_dataset) { ReeDaoLoadAggTest::UsersAggOnlyDataset.new }
319
336
  let(:organizations) { ReeDaoLoadAggTest::Organizations.new }
320
337
  let(:users) { ReeDaoLoadAggTest::Users.new }
321
338
  let(:user_passports) { ReeDaoLoadAggTest::UserPassports.new }
@@ -354,21 +371,41 @@ RSpec.describe :load_agg do
354
371
 
355
372
  res = users_agg_with_dto.call(
356
373
  users.all,
357
- to_dto: -> (users) {
358
- users.map do |user|
359
- ReeDaoLoadAggTest::UserDto.new(
360
- id: user.id,
361
- name: user.name,
362
- organization_id: user.organization_id,
363
- full_name: user.name
364
- )
365
- end
374
+ to_dto: -> (user) {
375
+ ReeDaoLoadAggTest::UserDto.new(
376
+ id: user.id,
377
+ name: user.name,
378
+ organization_id: user.organization_id,
379
+ full_name: user.name
380
+ )
366
381
  }
367
382
  )
368
383
 
369
- res_user = res[0]
384
+ expect(res.first.class).to eq(ReeDaoLoadAggTest::UserDto)
385
+ }
386
+
387
+ it {
388
+ organizations.delete_all
389
+ users.delete_all
390
+
391
+ org = ReeDaoLoadAggTest::Organization.new(name: "Test Org")
392
+ organizations.put(org)
393
+
394
+ user = ReeDaoLoadAggTest::User.new(name: "John", age: 33, organization_id: org.id)
395
+ users.put(user)
396
+
397
+ book_1 = ReeDaoLoadAggTest::Book.new(user_id: user.id, title: "1984")
398
+ book_2 = ReeDaoLoadAggTest::Book.new(user_id: user.id, title: "1408")
399
+ book_3 = ReeDaoLoadAggTest::Book.new(user_id: user.id, title: "1408")
400
+
401
+ books.put(book_1)
402
+ books.put(book_2)
403
+ books.put(book_3)
404
+
405
+ res = users_agg_only_dataset.call(users.where(name: "John"))
370
406
 
371
- expect(res_user.class).to eq(ReeDaoLoadAggTest::UserDto)
407
+ user = res[0]
408
+ expect(user.books.map(&:title).uniq).to eq(["1408"])
372
409
  }
373
410
 
374
411
  it {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.56"
4
+ VERSION = "1.0.57"
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.56
4
+ version: 1.0.57
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov