ree_lib 1.0.57 → 1.0.59
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 +4 -4
 - data/Gemfile.lock +1 -1
 - data/lib/ree_lib/packages/ree_dao/package/ree_dao/association.rb +22 -8
 - data/lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb +7 -6
 - data/lib/ree_lib/packages/ree_dao/package/ree_dao/functions/load_agg.rb +11 -2
 - data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/load_agg_spec.rb +44 -1
 - data/lib/ree_lib/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: ae96c3d6f51872601ad8c4a282cc8119e069a49a2942e624a3eed02817bbf450
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 962693ff78a273ff60ab20f1e704759038e0402619c84ce2da5735f16cca28ad
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 562c425026b16d0389287831ea2da44c08e79818c4f238e52f8e3ee0bb62bf36bc8e4bbfc75e3dbe658706a0b735c4c3e0e572287048e9a3095055e7183bfa62
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 54c6f30b6c62de9a43284fc76fcf432e9b0c70691de5d0aaf074c8b4cdb9b889f816ee8219c2ba4e660684899793db9a1c3cd7f502f5567fbe32d9df105b7a67
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
| 
         @@ -26,8 +26,8 @@ module ReeDao 
     | 
|
| 
       26 
26 
     | 
    
         
             
                  load_association(assoc_type, assoc_name, **opts, &block)
         
     | 
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
                def handle_field( 
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
      
 29 
     | 
    
         
            +
                def handle_field(field_proc)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  field_proc.call
         
     | 
| 
       31 
31 
     | 
    
         
             
                end
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
33 
     | 
    
         
             
                contract(
         
     | 
| 
         @@ -109,13 +109,24 @@ module ReeDao 
     | 
|
| 
       109 
109 
     | 
    
         
             
                      **global_opts
         
     | 
| 
       110 
110 
     | 
    
         
             
                    ).instance_exec(assoc_list, &block)
         
     | 
| 
       111 
111 
     | 
    
         
             
                  else
         
     | 
| 
       112 
     | 
    
         
            -
                    ReeDao::Associations.new(
         
     | 
| 
      
 112 
     | 
    
         
            +
                    threads = ReeDao::Associations.new(
         
     | 
| 
       113 
113 
     | 
    
         
             
                      parent.agg_caller,
         
     | 
| 
       114 
114 
     | 
    
         
             
                      assoc_list,
         
     | 
| 
       115 
115 
     | 
    
         
             
                      parent.local_vars,
         
     | 
| 
       116 
116 
     | 
    
         
             
                      autoload_children,
         
     | 
| 
       117 
117 
     | 
    
         
             
                      **global_opts
         
     | 
| 
       118 
     | 
    
         
            -
                    ).instance_exec(assoc_list, &block) 
     | 
| 
      
 118 
     | 
    
         
            +
                    ).instance_exec(assoc_list, &block)
         
     | 
| 
      
 119 
     | 
    
         
            +
                    threads[:association_threads].map do |association, assoc_type, assoc_name, opts, block|
         
     | 
| 
      
 120 
     | 
    
         
            +
                      Thread.new do
         
     | 
| 
      
 121 
     | 
    
         
            +
                        association.load(assoc_type, assoc_name, **opts, &block)
         
     | 
| 
      
 122 
     | 
    
         
            +
                      end
         
     | 
| 
      
 123 
     | 
    
         
            +
                    end.map(&:join)
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
                    threads[:field_threads].map do |association, field_proc|
         
     | 
| 
      
 126 
     | 
    
         
            +
                      Thread.new do
         
     | 
| 
      
 127 
     | 
    
         
            +
                        association.handle_field(field_proc)
         
     | 
| 
      
 128 
     | 
    
         
            +
                      end
         
     | 
| 
      
 129 
     | 
    
         
            +
                    end.map(&:join)
         
     | 
| 
       119 
130 
     | 
    
         
             
                  end
         
     | 
| 
       120 
131 
     | 
    
         
             
                end
         
     | 
| 
       121 
132 
     | 
    
         | 
| 
         @@ -231,7 +242,8 @@ module ReeDao 
     | 
|
| 
       231 
242 
     | 
    
         
             
                    assoc,
         
     | 
| 
       232 
243 
     | 
    
         
             
                    assoc_name,
         
     | 
| 
       233 
244 
     | 
    
         
             
                    setter: setter,
         
     | 
| 
       234 
     | 
    
         
            -
                    primary_key: primary_key
         
     | 
| 
      
 245 
     | 
    
         
            +
                    primary_key: primary_key,
         
     | 
| 
      
 246 
     | 
    
         
            +
                    multiple: true
         
     | 
| 
       235 
247 
     | 
    
         
             
                  )
         
     | 
| 
       236 
248 
     | 
    
         | 
| 
       237 
249 
     | 
    
         
             
                  assoc
         
     | 
| 
         @@ -244,10 +256,11 @@ module ReeDao 
     | 
|
| 
       244 
256 
     | 
    
         
             
                  Kwargs[
         
     | 
| 
       245 
257 
     | 
    
         
             
                    primary_key: Nilor[Symbol],
         
     | 
| 
       246 
258 
     | 
    
         
             
                    reverse: Nilor[Bool],
         
     | 
| 
       247 
     | 
    
         
            -
                    setter: Nilor[Or[Symbol, Proc]]
         
     | 
| 
      
 259 
     | 
    
         
            +
                    setter: Nilor[Or[Symbol, Proc]],
         
     | 
| 
      
 260 
     | 
    
         
            +
                    multiple: Bool
         
     | 
| 
       248 
261 
     | 
    
         
             
                  ] => Any
         
     | 
| 
       249 
262 
     | 
    
         
             
                )
         
     | 
| 
       250 
     | 
    
         
            -
                def populate_association(list, association_index, assoc_name, primary_key: nil, reverse: nil, setter: nil)
         
     | 
| 
      
 263 
     | 
    
         
            +
                def populate_association(list, association_index, assoc_name, primary_key: nil, reverse: nil, setter: nil, multiple: false)
         
     | 
| 
       251 
264 
     | 
    
         
             
                  assoc_setter = if setter
         
     | 
| 
       252 
265 
     | 
    
         
             
                    setter
         
     | 
| 
       253 
266 
     | 
    
         
             
                  else
         
     | 
| 
         @@ -264,7 +277,8 @@ module ReeDao 
     | 
|
| 
       264 
277 
     | 
    
         
             
                        reverse ? primary_key : "#{assoc_name}_id"
         
     | 
| 
       265 
278 
     | 
    
         
             
                      end
         
     | 
| 
       266 
279 
     | 
    
         
             
                      value = association_index[item.send(key)]
         
     | 
| 
       267 
     | 
    
         
            -
             
     | 
| 
      
 280 
     | 
    
         
            +
             
     | 
| 
      
 281 
     | 
    
         
            +
                      value = [] if value.nil? && multiple
         
     | 
| 
       268 
282 
     | 
    
         | 
| 
       269 
283 
     | 
    
         
             
                      begin
         
     | 
| 
       270 
284 
     | 
    
         
             
                        item.send(assoc_setter, value)
         
     | 
| 
         @@ -97,17 +97,18 @@ module ReeDao 
     | 
|
| 
       97 
97 
     | 
    
         
             
                    association = Association.new(self, list, **global_opts)
         
     | 
| 
       98 
98 
     | 
    
         | 
| 
       99 
99 
     | 
    
         
             
                    if assoc_type == :field
         
     | 
| 
      
 100 
     | 
    
         
            +
                      field_proc = opts
         
     | 
| 
       100 
101 
     | 
    
         
             
                      { 
         
     | 
| 
       101 
102 
     | 
    
         
             
                        association_threads: @assoc_threads,
         
     | 
| 
       102 
     | 
    
         
            -
                        field_threads: @field_threads <<  
     | 
| 
       103 
     | 
    
         
            -
                          association 
     | 
| 
       104 
     | 
    
         
            -
                         
     | 
| 
      
 103 
     | 
    
         
            +
                        field_threads: @field_threads << [
         
     | 
| 
      
 104 
     | 
    
         
            +
                          association, field_proc
         
     | 
| 
      
 105 
     | 
    
         
            +
                        ]
         
     | 
| 
       105 
106 
     | 
    
         
             
                      }
         
     | 
| 
       106 
107 
     | 
    
         
             
                    else
         
     | 
| 
       107 
108 
     | 
    
         
             
                      {
         
     | 
| 
       108 
     | 
    
         
            -
                        association_threads: @assoc_threads <<  
     | 
| 
       109 
     | 
    
         
            -
                          association 
     | 
| 
       110 
     | 
    
         
            -
                         
     | 
| 
      
 109 
     | 
    
         
            +
                        association_threads: @assoc_threads << [
         
     | 
| 
      
 110 
     | 
    
         
            +
                          association, assoc_type, assoc_name, get_assoc_opts(opts), block
         
     | 
| 
      
 111 
     | 
    
         
            +
                        ],
         
     | 
| 
       111 
112 
     | 
    
         
             
                        field_threads: @field_threads
         
     | 
| 
       112 
113 
     | 
    
         
             
                      }
         
     | 
| 
       113 
114 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -68,8 +68,17 @@ class ReeDao::LoadAgg 
     | 
|
| 
       68 
68 
     | 
    
         
             
                if ReeDao.load_sync_associations_enabled?
         
     | 
| 
       69 
69 
     | 
    
         
             
                  associations
         
     | 
| 
       70 
70 
     | 
    
         
             
                else
         
     | 
| 
       71 
     | 
    
         
            -
                  associations[:association_threads].map 
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
      
 71 
     | 
    
         
            +
                  associations[:association_threads].map do |association, assoc_type, assoc_name, opts, block|
         
     | 
| 
      
 72 
     | 
    
         
            +
                    Thread.new do
         
     | 
| 
      
 73 
     | 
    
         
            +
                      association.load(assoc_type, assoc_name, **opts, &block)
         
     | 
| 
      
 74 
     | 
    
         
            +
                    end
         
     | 
| 
      
 75 
     | 
    
         
            +
                  end.map(&:join)
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                  associations[:field_threads].map do |association, field_proc|
         
     | 
| 
      
 78 
     | 
    
         
            +
                    Thread.new do
         
     | 
| 
      
 79 
     | 
    
         
            +
                      association.handle_field(field_proc)
         
     | 
| 
      
 80 
     | 
    
         
            +
                    end
         
     | 
| 
      
 81 
     | 
    
         
            +
                  end.map(&:join)
         
     | 
| 
       73 
82 
     | 
    
         
             
                end
         
     | 
| 
       74 
83 
     | 
    
         
             
              end
         
     | 
| 
       75 
84 
     | 
    
         
             
            end
         
     | 
| 
         @@ -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
         
     | 
| 
       279 
279 
     | 
    
         | 
| 
       280 
280 
     | 
    
         
             
                    has_many :books, -> { books_opts(title) }
         
     | 
| 
       281 
281 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -465,6 +465,49 @@ RSpec.describe :load_agg do 
     | 
|
| 
       465 
465 
     | 
    
         
             
                expect(res_user.custom_field).to_not eq(nil)
         
     | 
| 
       466 
466 
     | 
    
         
             
              }
         
     | 
| 
       467 
467 
     | 
    
         | 
| 
      
 468 
     | 
    
         
            +
              it {
         
     | 
| 
      
 469 
     | 
    
         
            +
                organizations.delete_all
         
     | 
| 
      
 470 
     | 
    
         
            +
                users.delete_all
         
     | 
| 
      
 471 
     | 
    
         
            +
                user_passports.delete_all
         
     | 
| 
      
 472 
     | 
    
         
            +
                books.delete_all
         
     | 
| 
      
 473 
     | 
    
         
            +
                chapters.delete_all
         
     | 
| 
      
 474 
     | 
    
         
            +
             
     | 
| 
      
 475 
     | 
    
         
            +
                organization = ReeDaoLoadAggTest::Organization.new(name: "Test Org")
         
     | 
| 
      
 476 
     | 
    
         
            +
                organizations.put(organization)
         
     | 
| 
      
 477 
     | 
    
         
            +
             
     | 
| 
      
 478 
     | 
    
         
            +
                user_1 = ReeDaoLoadAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
         
     | 
| 
      
 479 
     | 
    
         
            +
                user_2 = ReeDaoLoadAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
         
     | 
| 
      
 480 
     | 
    
         
            +
                users.put(user_1)
         
     | 
| 
      
 481 
     | 
    
         
            +
                users.put(user_2)
         
     | 
| 
      
 482 
     | 
    
         
            +
             
     | 
| 
      
 483 
     | 
    
         
            +
                book_1 = ReeDaoLoadAggTest::Book.new(user_id: user_1.id, title: "1984")
         
     | 
| 
      
 484 
     | 
    
         
            +
                book_2 = ReeDaoLoadAggTest::Book.new(user_id: user_1.id, title: "1408")
         
     | 
| 
      
 485 
     | 
    
         
            +
             
     | 
| 
      
 486 
     | 
    
         
            +
                books.put(book_1)
         
     | 
| 
      
 487 
     | 
    
         
            +
                books.put(book_2)
         
     | 
| 
      
 488 
     | 
    
         
            +
             
     | 
| 
      
 489 
     | 
    
         
            +
                author_1 = ReeDaoLoadAggTest::Author.new(book_id: book_1.id, name: "George Orwell")
         
     | 
| 
      
 490 
     | 
    
         
            +
                author_2 = ReeDaoLoadAggTest::Author.new(book_id: book_2.id, name: "Stephen King")
         
     | 
| 
      
 491 
     | 
    
         
            +
                authors.put(author_1)
         
     | 
| 
      
 492 
     | 
    
         
            +
                authors.put(author_2)
         
     | 
| 
      
 493 
     | 
    
         
            +
             
     | 
| 
      
 494 
     | 
    
         
            +
                res = users_agg.call(
         
     | 
| 
      
 495 
     | 
    
         
            +
                  users.all
         
     | 
| 
      
 496 
     | 
    
         
            +
                )
         
     | 
| 
      
 497 
     | 
    
         
            +
             
     | 
| 
      
 498 
     | 
    
         
            +
                expect(res[0].books.first.author).to_not eq(nil)
         
     | 
| 
      
 499 
     | 
    
         
            +
             
     | 
| 
      
 500 
     | 
    
         
            +
                authors.delete(author_1)
         
     | 
| 
      
 501 
     | 
    
         
            +
                authors.delete(author_2)
         
     | 
| 
      
 502 
     | 
    
         
            +
             
     | 
| 
      
 503 
     | 
    
         
            +
                res = users_agg.call(
         
     | 
| 
      
 504 
     | 
    
         
            +
                  users.all
         
     | 
| 
      
 505 
     | 
    
         
            +
                )
         
     | 
| 
      
 506 
     | 
    
         
            +
             
     | 
| 
      
 507 
     | 
    
         
            +
                expect(res[0].books[0].author).to eq(nil)
         
     | 
| 
      
 508 
     | 
    
         
            +
                expect(res[0].books[1].author).to eq(nil)
         
     | 
| 
      
 509 
     | 
    
         
            +
              }
         
     | 
| 
      
 510 
     | 
    
         
            +
             
     | 
| 
       468 
511 
     | 
    
         
             
              it {
         
     | 
| 
       469 
512 
     | 
    
         
             
                organizations.delete_all
         
     | 
| 
       470 
513 
     | 
    
         
             
                users.delete_all
         
     | 
    
        data/lib/ree_lib/version.rb
    CHANGED