ree_lib 1.1.0 → 1.2.0

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.
Files changed (24) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile.lock +30 -30
  4. data/lib/ree_lib/packages/ree_dao/package/ree_dao/build_methods.rb +14 -0
  5. data/lib/ree_lib/packages/ree_dao/package/ree_dao/functions/build_connection.rb +2 -0
  6. data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/build_dto_spec.rb +69 -0
  7. data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/agg_spec.rb +128 -128
  8. data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/one_to_one_spec.rb +1 -1
  9. data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/persist_assoc_spec.rb +4 -4
  10. data/lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb +11 -4
  11. data/lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_class_methods.rb +21 -0
  12. data/lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_instance_methods.rb +8 -10
  13. data/lib/ree_lib/packages/ree_dto/package/ree_dto/dto/field_meta.rb +4 -3
  14. data/lib/ree_lib/packages/ree_dto/package/ree_dto/functions/build_dto.rb +1 -0
  15. data/lib/ree_lib/packages/ree_dto/spec/ree_dto/dsl_spec.rb +46 -5
  16. data/lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb +3 -5
  17. data/lib/ree_lib/packages/ree_errors/package/ree_errors/invalid_param_error.rb +1 -1
  18. data/lib/ree_lib/packages/ree_errors/spec/ree_errors/invalid_param_error_spec.rb +13 -1
  19. data/lib/ree_lib/packages/ree_logger/spec/ree_logger/formatters/colorized_formatter_spec.rb +10 -3
  20. data/lib/ree_lib/packages/ree_logger/spec/ree_logger/formatters/default_formatter_spec.rb +6 -2
  21. data/lib/ree_lib/packages/ree_logger/spec/ree_logger/multi_logger_spec.rb +13 -3
  22. data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/strategy_outputs/ree_dto_output.rb +1 -1
  23. data/lib/ree_lib/version.rb +1 -1
  24. metadata +31 -32
@@ -395,10 +395,10 @@ RSpec.describe :agg do
395
395
  organizations.delete_all
396
396
  users.delete_all
397
397
 
398
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
398
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
399
399
  organizations.put(organization)
400
400
 
401
- user = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
401
+ user = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
402
402
  users.put(user)
403
403
 
404
404
  expect {
@@ -413,37 +413,37 @@ RSpec.describe :agg do
413
413
  books.delete_all
414
414
  chapters.delete_all
415
415
 
416
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
416
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
417
417
  organizations.put(organization)
418
418
 
419
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
420
- user_2 = ReeDaoAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
419
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
420
+ user_2 = ReeDaoAggTest::User.build(name: "Sam", age: 21, organization_id: organization.id)
421
421
  users.put(user_1)
422
422
  users.put(user_2)
423
423
 
424
- passport_1 = ReeDaoAggTest::UserPassport.new(user_id: user_1.id, info: "some info")
424
+ passport_1 = ReeDaoAggTest::UserPassport.build(user_id: user_1.id, info: "some info")
425
425
  user_passports.put(passport_1)
426
- user_passports.put(ReeDaoAggTest::UserPassport.new(user_id: user_2.id, info: "another info"))
426
+ user_passports.put(ReeDaoAggTest::UserPassport.build(user_id: user_2.id, info: "another info"))
427
427
 
428
- book_1 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1984")
429
- book_2 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1408")
428
+ book_1 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1984")
429
+ book_2 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1408")
430
430
 
431
431
  books.put(book_1)
432
432
  books.put(book_2)
433
433
 
434
- chapter = ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "beginning")
434
+ chapter = ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "beginning")
435
435
  chapters.put(chapter)
436
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "interlude"))
437
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "tragic ending"))
438
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_2.id, title: "beginning"))
439
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_2.id, title: "ending"))
436
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "interlude"))
437
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "tragic ending"))
438
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_2.id, title: "beginning"))
439
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_2.id, title: "ending"))
440
440
 
441
441
 
442
- authors.put(ReeDaoAggTest::Author.new(book_id: book_1.id, name: "George Orwell"))
443
- review = ReeDaoAggTest::Review.new(book_id: book_1.id, rating: 10)
442
+ authors.put(ReeDaoAggTest::Author.build(book_id: book_1.id, name: "George Orwell"))
443
+ review = ReeDaoAggTest::Review.build(book_id: book_1.id, rating: 10)
444
444
  reviews.put(review)
445
- reviews.put(ReeDaoAggTest::Review.new(book_id: book_1.id, rating: 7))
446
- review_authors.put(ReeDaoAggTest::ReviewAuthor.new(review_id: review.id, name: "John Review"))
445
+ reviews.put(ReeDaoAggTest::Review.build(book_id: book_1.id, rating: 7))
446
+ review_authors.put(ReeDaoAggTest::ReviewAuthor.build(review_id: review.id, name: "John Review"))
447
447
 
448
448
  res = agg_users.call(
449
449
  users.all,
@@ -458,10 +458,10 @@ RSpec.describe :agg do
458
458
  organizations.delete_all
459
459
  users.delete_all
460
460
 
461
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
461
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
462
462
  organizations.put(organization)
463
463
 
464
- user = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
464
+ user = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
465
465
  users.put(user)
466
466
 
467
467
  expect {
@@ -473,24 +473,24 @@ RSpec.describe :agg do
473
473
  organizations.delete_all
474
474
  users.delete_all
475
475
 
476
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
476
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
477
477
  organizations.put(organization)
478
478
 
479
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
480
- user_2 = ReeDaoAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
479
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
480
+ user_2 = ReeDaoAggTest::User.build(name: "Sam", age: 21, organization_id: organization.id)
481
481
  users.put(user_1)
482
482
  users.put(user_2)
483
483
 
484
- book_1 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1984")
484
+ book_1 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1984")
485
485
  books.put(book_1)
486
486
 
487
- authors.put(ReeDaoAggTest::Author.new(book_id: book_1.id, name: "George Orwell"))
488
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "interlude"))
487
+ authors.put(ReeDaoAggTest::Author.build(book_id: book_1.id, name: "George Orwell"))
488
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "interlude"))
489
489
 
490
490
  res = agg_users_with_dto.call(
491
491
  users.all,
492
492
  to_dto: -> (user) {
493
- ReeDaoAggTest::UserDto.new(
493
+ ReeDaoAggTest::UserDto.build(
494
494
  id: user.id,
495
495
  name: user.name,
496
496
  organization_id: user.organization_id,
@@ -511,15 +511,15 @@ RSpec.describe :agg do
511
511
  organizations.delete_all
512
512
  users.delete_all
513
513
 
514
- org = ReeDaoAggTest::Organization.new(name: "Test Org")
514
+ org = ReeDaoAggTest::Organization.build(name: "Test Org")
515
515
  organizations.put(org)
516
516
 
517
- user = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: org.id)
517
+ user = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: org.id)
518
518
  users.put(user)
519
519
 
520
- book_1 = ReeDaoAggTest::Book.new(user_id: user.id, title: "1984")
521
- book_2 = ReeDaoAggTest::Book.new(user_id: user.id, title: "1408")
522
- book_3 = ReeDaoAggTest::Book.new(user_id: user.id, title: "1408")
520
+ book_1 = ReeDaoAggTest::Book.build(user_id: user.id, title: "1984")
521
+ book_2 = ReeDaoAggTest::Book.build(user_id: user.id, title: "1408")
522
+ book_3 = ReeDaoAggTest::Book.build(user_id: user.id, title: "1408")
523
523
 
524
524
  books.put(book_1)
525
525
  books.put(book_2)
@@ -538,37 +538,37 @@ RSpec.describe :agg do
538
538
  books.delete_all
539
539
  chapters.delete_all
540
540
 
541
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
541
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
542
542
  organizations.put(organization)
543
543
 
544
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
545
- user_2 = ReeDaoAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
544
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
545
+ user_2 = ReeDaoAggTest::User.build(name: "Sam", age: 21, organization_id: organization.id)
546
546
  users.put(user_1)
547
547
  users.put(user_2)
548
548
 
549
- passport_1 = ReeDaoAggTest::UserPassport.new(user_id: user_1.id, info: "some info")
549
+ passport_1 = ReeDaoAggTest::UserPassport.build(user_id: user_1.id, info: "some info")
550
550
  user_passports.put(passport_1)
551
- user_passports.put(ReeDaoAggTest::UserPassport.new(user_id: user_2.id, info: "another info"))
551
+ user_passports.put(ReeDaoAggTest::UserPassport.build(user_id: user_2.id, info: "another info"))
552
552
 
553
- book_1 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1984")
554
- book_2 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1408")
553
+ book_1 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1984")
554
+ book_2 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1408")
555
555
 
556
556
  books.put(book_1)
557
557
  books.put(book_2)
558
558
 
559
- chapter = ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "beginning")
559
+ chapter = ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "beginning")
560
560
  chapters.put(chapter)
561
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "interlude"))
562
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "tragic ending"))
563
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_2.id, title: "beginning"))
564
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_2.id, title: "ending"))
561
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "interlude"))
562
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "tragic ending"))
563
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_2.id, title: "beginning"))
564
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_2.id, title: "ending"))
565
565
 
566
566
 
567
- authors.put(ReeDaoAggTest::Author.new(book_id: book_1.id, name: "George Orwell"))
568
- review = ReeDaoAggTest::Review.new(book_id: book_1.id, rating: 10)
567
+ authors.put(ReeDaoAggTest::Author.build(book_id: book_1.id, name: "George Orwell"))
568
+ review = ReeDaoAggTest::Review.build(book_id: book_1.id, rating: 10)
569
569
  reviews.put(review)
570
- reviews.put(ReeDaoAggTest::Review.new(book_id: book_1.id, rating: 7))
571
- review_authors.put(ReeDaoAggTest::ReviewAuthor.new(review_id: review.id, name: "John Review"))
570
+ reviews.put(ReeDaoAggTest::Review.build(book_id: book_1.id, rating: 7))
571
+ review_authors.put(ReeDaoAggTest::ReviewAuthor.build(review_id: review.id, name: "John Review"))
572
572
 
573
573
  res = agg_users.call(
574
574
  users.all,
@@ -595,22 +595,22 @@ RSpec.describe :agg do
595
595
  books.delete_all
596
596
  chapters.delete_all
597
597
 
598
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
598
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
599
599
  organizations.put(organization)
600
600
 
601
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
602
- user_2 = ReeDaoAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
601
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
602
+ user_2 = ReeDaoAggTest::User.build(name: "Sam", age: 21, organization_id: organization.id)
603
603
  users.put(user_1)
604
604
  users.put(user_2)
605
605
 
606
- book_1 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1984")
607
- book_2 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1408")
606
+ book_1 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1984")
607
+ book_2 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1408")
608
608
 
609
609
  books.put(book_1)
610
610
  books.put(book_2)
611
611
 
612
- author_1 = ReeDaoAggTest::Author.new(book_id: book_1.id, name: "George Orwell")
613
- author_2 = ReeDaoAggTest::Author.new(book_id: book_2.id, name: "Stephen King")
612
+ author_1 = ReeDaoAggTest::Author.build(book_id: book_1.id, name: "George Orwell")
613
+ author_2 = ReeDaoAggTest::Author.build(book_id: book_2.id, name: "Stephen King")
614
614
  authors.put(author_1)
615
615
  authors.put(author_2)
616
616
 
@@ -638,16 +638,16 @@ RSpec.describe :agg do
638
638
  books.delete_all
639
639
  chapters.delete_all
640
640
 
641
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
641
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
642
642
  organizations.put(organization)
643
643
 
644
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
645
- user_2 = ReeDaoAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
644
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
645
+ user_2 = ReeDaoAggTest::User.build(name: "Sam", age: 21, organization_id: organization.id)
646
646
  users.put(user_1)
647
647
  users.put(user_2)
648
648
 
649
- book_1 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1984")
650
- book_2 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1408")
649
+ book_1 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1984")
650
+ book_2 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1408")
651
651
 
652
652
  books.put(book_1)
653
653
  books.put(book_2)
@@ -675,16 +675,16 @@ RSpec.describe :agg do
675
675
  users.delete_all
676
676
  books.delete_all
677
677
 
678
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
678
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
679
679
  organizations.put(organization)
680
680
 
681
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
682
- user_2 = ReeDaoAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
681
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
682
+ user_2 = ReeDaoAggTest::User.build(name: "Sam", age: 21, organization_id: organization.id)
683
683
  users.put(user_1)
684
684
  users.put(user_2)
685
685
 
686
- book_1 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1984")
687
- book_2 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1408")
686
+ book_1 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1984")
687
+ book_2 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1408")
688
688
 
689
689
  books.put(book_1)
690
690
  books.put(book_2)
@@ -703,16 +703,16 @@ RSpec.describe :agg do
703
703
  users.delete_all
704
704
  books.delete_all
705
705
 
706
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
706
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
707
707
  organizations.put(organization)
708
708
 
709
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
710
- user_2 = ReeDaoAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
709
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
710
+ user_2 = ReeDaoAggTest::User.build(name: "Sam", age: 21, organization_id: organization.id)
711
711
  users.put(user_1)
712
712
  users.put(user_2)
713
713
 
714
- book_1 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1984")
715
- book_2 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1408")
714
+ book_1 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1984")
715
+ book_2 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1408")
716
716
 
717
717
  books.put(book_1)
718
718
  books.put(book_2)
@@ -729,23 +729,23 @@ RSpec.describe :agg do
729
729
  books.delete_all
730
730
  chapters.delete_all
731
731
 
732
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
732
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
733
733
  organizations.put(organization)
734
734
 
735
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
735
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
736
736
  users.put(user_1)
737
737
 
738
- book_1 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1984")
739
- book_2 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1408")
738
+ book_1 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1984")
739
+ book_2 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1408")
740
740
 
741
741
  books.put(book_1)
742
742
  books.put(book_2)
743
743
 
744
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "beginning"))
745
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "interlude"))
746
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "tragic ending"))
747
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_2.id, title: "beginning"))
748
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_2.id, title: "ending"))
744
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "beginning"))
745
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "interlude"))
746
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "tragic ending"))
747
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_2.id, title: "beginning"))
748
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_2.id, title: "ending"))
749
749
 
750
750
  res = agg_users.call(
751
751
  users.all,
@@ -764,23 +764,23 @@ RSpec.describe :agg do
764
764
  books.delete_all
765
765
  chapters.delete_all
766
766
 
767
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
767
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
768
768
  organizations.put(organization)
769
769
 
770
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
770
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
771
771
  users.put(user_1)
772
772
 
773
- book_1 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1984")
774
- book_2 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1408")
773
+ book_1 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1984")
774
+ book_2 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1408")
775
775
 
776
776
  books.put(book_1)
777
777
  books.put(book_2)
778
778
 
779
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "beginning"))
780
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "interlude"))
781
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "tragic ending"))
782
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_2.id, title: "beginning"))
783
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_2.id, title: "ending"))
779
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "beginning"))
780
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "interlude"))
781
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "tragic ending"))
782
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_2.id, title: "beginning"))
783
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_2.id, title: "ending"))
784
784
 
785
785
  res = agg_users.call(
786
786
  users.all,
@@ -799,24 +799,24 @@ RSpec.describe :agg do
799
799
  books.delete_all
800
800
  chapters.delete_all
801
801
 
802
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
802
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
803
803
  organizations.put(organization)
804
804
 
805
- user = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
805
+ user = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
806
806
  users.put(user)
807
807
 
808
- book = ReeDaoAggTest::Book.new(user_id: user.id, title: "1984")
808
+ book = ReeDaoAggTest::Book.build(user_id: user.id, title: "1984")
809
809
  books.put(book)
810
810
 
811
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book.id, title: "beginning"))
812
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book.id, title: "interlude"))
813
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book.id, title: "tragic ending"))
811
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book.id, title: "beginning"))
812
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book.id, title: "interlude"))
813
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book.id, title: "tragic ending"))
814
814
 
815
- authors.put(ReeDaoAggTest::Author.new(book_id: book.id, name: "George Orwell"))
815
+ authors.put(ReeDaoAggTest::Author.build(book_id: book.id, name: "George Orwell"))
816
816
 
817
- review = ReeDaoAggTest::Review.new(book_id: book.id, rating: 5)
817
+ review = ReeDaoAggTest::Review.build(book_id: book.id, rating: 5)
818
818
  reviews.put(review)
819
- review_authors.put(ReeDaoAggTest::ReviewAuthor.new(review_id: review.id, name: "John"))
819
+ review_authors.put(ReeDaoAggTest::ReviewAuthor.build(review_id: review.id, name: "John"))
820
820
 
821
821
  res = agg_users_autoload_books_children.call(
822
822
  users.all,
@@ -838,24 +838,24 @@ RSpec.describe :agg do
838
838
  books.delete_all
839
839
  chapters.delete_all
840
840
 
841
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
841
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
842
842
  organizations.put(organization)
843
843
 
844
- user = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
844
+ user = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
845
845
  users.put(user)
846
846
 
847
- book = ReeDaoAggTest::Book.new(user_id: user.id, title: "1984")
847
+ book = ReeDaoAggTest::Book.build(user_id: user.id, title: "1984")
848
848
  books.put(book)
849
849
 
850
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book.id, title: "beginning"))
851
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book.id, title: "interlude"))
852
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book.id, title: "tragic ending"))
850
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book.id, title: "beginning"))
851
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book.id, title: "interlude"))
852
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book.id, title: "tragic ending"))
853
853
 
854
- authors.put(ReeDaoAggTest::Author.new(book_id: book.id, name: "George Orwell"))
854
+ authors.put(ReeDaoAggTest::Author.build(book_id: book.id, name: "George Orwell"))
855
855
 
856
- review = ReeDaoAggTest::Review.new(book_id: book.id, rating: 5)
856
+ review = ReeDaoAggTest::Review.build(book_id: book.id, rating: 5)
857
857
  reviews.put(review)
858
- review_authors.put(ReeDaoAggTest::ReviewAuthor.new(review_id: review.id, name: "John"))
858
+ review_authors.put(ReeDaoAggTest::ReviewAuthor.build(review_id: review.id, name: "John"))
859
859
 
860
860
  res = agg_users_autoload_reviews_children.call(
861
861
  users.all,
@@ -876,13 +876,13 @@ RSpec.describe :agg do
876
876
  user_passports.delete_all
877
877
  books.delete_all
878
878
 
879
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
879
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
880
880
  organizations.put(organization)
881
881
 
882
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
882
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
883
883
  users.put(user_1)
884
884
 
885
- book_1 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1984")
885
+ book_1 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1984")
886
886
 
887
887
  books.put(book_1)
888
888
 
@@ -899,23 +899,23 @@ RSpec.describe :agg do
899
899
  books.delete_all
900
900
  chapters.delete_all
901
901
 
902
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
902
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
903
903
  organizations.put(organization)
904
904
 
905
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
905
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
906
906
  users.put(user_1)
907
907
 
908
- book_1 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1984")
909
- book_2 = ReeDaoAggTest::Book.new(user_id: user_1.id, title: "1408")
908
+ book_1 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1984")
909
+ book_2 = ReeDaoAggTest::Book.build(user_id: user_1.id, title: "1408")
910
910
 
911
911
  books.put(book_1)
912
912
  books.put(book_2)
913
913
 
914
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "beginning"))
915
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "interlude"))
916
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_1.id, title: "tragic ending"))
917
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_2.id, title: "beginning"))
918
- chapters.put(ReeDaoAggTest::Chapter.new(book_id: book_2.id, title: "ending"))
914
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "beginning"))
915
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "interlude"))
916
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_1.id, title: "tragic ending"))
917
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_2.id, title: "beginning"))
918
+ chapters.put(ReeDaoAggTest::Chapter.build(book_id: book_2.id, title: "ending"))
919
919
 
920
920
  res = agg_users.call(
921
921
  users.all,
@@ -933,11 +933,11 @@ RSpec.describe :agg do
933
933
  organizations.delete_all
934
934
  users.delete_all
935
935
 
936
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
936
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
937
937
  organizations.put(organization)
938
938
 
939
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
940
- user_2 = ReeDaoAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
939
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
940
+ user_2 = ReeDaoAggTest::User.build(name: "Sam", age: 21, organization_id: organization.id)
941
941
  users.put(user_1)
942
942
  users.put(user_2)
943
943
 
@@ -951,10 +951,10 @@ RSpec.describe :agg do
951
951
  organizations.delete_all
952
952
  users.delete_all
953
953
 
954
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
954
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
955
955
  organizations.put(organization)
956
956
 
957
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
957
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
958
958
  users.put(user_1)
959
959
 
960
960
  res = agg(users, user_1.id)
@@ -965,11 +965,11 @@ RSpec.describe :agg do
965
965
  organizations.delete_all
966
966
  users.delete_all
967
967
 
968
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
968
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
969
969
  organizations.put(organization)
970
970
 
971
- user_1 = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
972
- user_2 = ReeDaoAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
971
+ user_1 = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
972
+ user_2 = ReeDaoAggTest::User.build(name: "Sam", age: 21, organization_id: organization.id)
973
973
  users.put(user_1)
974
974
  users.put(user_2)
975
975
 
@@ -979,9 +979,9 @@ RSpec.describe :agg do
979
979
 
980
980
  context "when sync mode enabled" do
981
981
  it {
982
- organization = ReeDaoAggTest::Organization.new(name: "Test Org")
982
+ organization = ReeDaoAggTest::Organization.build(name: "Test Org")
983
983
  organizations.put(organization)
984
- user = ReeDaoAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
984
+ user = ReeDaoAggTest::User.build(name: "John", age: 33, organization_id: organization.id)
985
985
  users.put(user)
986
986
 
987
987
  allow(user).to receive(:some_field=)
@@ -128,7 +128,7 @@ RSpec.describe :one_to_one do
128
128
  project = TestOneToOne::Project.new(id: 1)
129
129
 
130
130
  project.set_project_user(
131
- TestOneToOne::ProjectUser.new
131
+ TestOneToOne::ProjectUser.build
132
132
  )
133
133
 
134
134
  TestOneToOne::ProjectsDao.new.put(project)
@@ -112,11 +112,11 @@ RSpec.describe :persist_assoc do
112
112
  project = TestPersistAssoc::Project.new(id: 1)
113
113
 
114
114
  project.add_project_user(
115
- TestPersistAssoc::ProjectUser.new
115
+ TestPersistAssoc::ProjectUser.build
116
116
  )
117
117
 
118
118
  project.add_project_user(
119
- TestPersistAssoc::ProjectUser.new
119
+ TestPersistAssoc::ProjectUser.build
120
120
  )
121
121
 
122
122
  TestPersistAssoc::ProjectsDao.new.put(project)
@@ -138,11 +138,11 @@ RSpec.describe :persist_assoc do
138
138
  project = TestPersistAssoc::Project.new(id: 2)
139
139
 
140
140
  project.add_project_user(
141
- TestPersistAssoc::ProjectUser.new
141
+ TestPersistAssoc::ProjectUser.build
142
142
  )
143
143
 
144
144
  project.add_project_user(
145
- TestPersistAssoc::ProjectUser.new
145
+ TestPersistAssoc::ProjectUser.build
146
146
  )
147
147
 
148
148
  TestPersistAssoc::ProjectsDao.new.put(project)
@@ -6,27 +6,34 @@ class ReeDto::DtoBuilder
6
6
  link "ree_dto/dto/field_meta", -> { FieldMeta }
7
7
  link "ree_dto/dto/collection_meta", -> { CollectionMeta }
8
8
 
9
- attr_reader :fields, :collections
9
+ attr_reader :fields, :fields_with_default, :collections
10
10
 
11
11
  def initialize(klass)
12
12
  @klass = klass
13
13
  @fields = []
14
+ @fields_with_default = []
14
15
  @collections = []
15
16
  end
16
17
 
17
- contract(Symbol, Any, Kwargs[setter: Bool, default: Any] => FieldMeta)
18
- def field(name, contract, setter: true, default: FieldMeta::NONE)
18
+ contract(Symbol, Any, Kwargs[setter: Bool, default: Any, field_type: Symbol] => FieldMeta)
19
+ def field(name, contract, setter: true, default: FieldMeta::NONE, field_type: :custom)
19
20
  existing = @fields.find { _1.name == name }
20
21
 
21
22
  if existing
22
23
  raise ArgumentError.new("field :#{name} already defined for #{@klass}")
23
24
  end
24
25
 
25
- field = FieldMeta.new(name, contract, setter, default)
26
+ field = FieldMeta.new(name, contract, setter, default, field_type)
26
27
  @fields << field
28
+ @fields_with_default << field if field.has_default?
27
29
  field
28
30
  end
29
31
 
32
+ contract(Symbol, Any, Kwargs[setter: Bool, default: Any] => FieldMeta)
33
+ def db_field(name, contract, setter: true, default: FieldMeta::NONE)
34
+ field(name, contract, setter: setter, default: default, field_type: :db)
35
+ end
36
+
30
37
  contract Symbol, Any, Optblock => CollectionMeta
31
38
  def collection(name, contract, &proc)
32
39
  existing = @collections.find { _1.name == name }
@@ -10,17 +10,38 @@ module ReeDto::DtoClassMethods
10
10
  @fields ||= []
11
11
  end
12
12
 
13
+ contract None => ArrayOf[ReeDto::FieldMeta]
14
+ def fields_with_default
15
+ @fields_with_default ||= []
16
+ end
17
+
13
18
  contract None => ArrayOf[ReeDto::CollectionMeta]
14
19
  def collections
15
20
  @collections ||= []
16
21
  end
17
22
 
23
+ def build(attrs = nil, **kwargs)
24
+ dto_obj = new(attrs || kwargs)
25
+ set_attrs = attrs ? attrs.keys : kwargs.keys
26
+ fields_to_set = fields_with_default.reject{ set_attrs.include?(_1.name) }
27
+
28
+ fields_to_set.each do |field|
29
+ dto_obj.set_attr(field.name, field.default)
30
+ end
31
+
32
+ dto_obj
33
+ end
34
+
18
35
  private
19
36
 
20
37
  def set_fields(v)
21
38
  @fields = v
22
39
  end
23
40
 
41
+ def set_fields_with_default(v)
42
+ @fields_with_default = v
43
+ end
44
+
24
45
  def set_collections(v)
25
46
  @collections = v
26
47
  end