occams-record 1.5.0 → 1.6.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.
- checksums.yaml +4 -4
 - data/README.md +12 -12
 - data/lib/occams-record/eager_loaders/ad_hoc_base.rb +7 -1
 - data/lib/occams-record/eager_loaders/base.rb +7 -1
 - data/lib/occams-record/eager_loaders/builder.rb +6 -0
 - data/lib/occams-record/eager_loaders/polymorphic_belongs_to.rb +7 -1
 - data/lib/occams-record/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a367407e2af3e4110327d26438fcb2a590b7fbd34e6b60dd4bd9396665c495fe
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8cf6fb913ac787126a80fe38baff3a56940cea8afc80e1b05e3c864ae8368e11
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2bc45d11bc974e5a5ec6b2b9ffab8e3f069048ee8335122ad81a8b49cc852fa4bdb27116865000e4b70e4f6d617b3f870861288e00a43b273e3ec14d0dfdb6b6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: af1dac7260e93ed3778ff022c3d6113819528e37d77c275b9cada6cd5e731593bbe9e4f24ae283ed572a4876672126df4cb002ab8f9c863e3de4943f95acdbc2
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -20,8 +20,8 @@ Continue using ActiveRecord's query builder, but let Occams take over running th 
     | 
|
| 
       20 
20 
     | 
    
         
             
            ```ruby
         
     | 
| 
       21 
21 
     | 
    
         
             
            OccamsRecord
         
     | 
| 
       22 
22 
     | 
    
         
             
              .query(User.active)
         
     | 
| 
       23 
     | 
    
         
            -
              .eager_load(:orders) {
         
     | 
| 
       24 
     | 
    
         
            -
                scope { |q| q.where("created_at >= ?", date).order("created_at DESC") }
         
     | 
| 
      
 23 
     | 
    
         
            +
              .eager_load(:orders) { |l|
         
     | 
| 
      
 24 
     | 
    
         
            +
                l.scope { |q| q.where("created_at >= ?", date).order("created_at DESC") }
         
     | 
| 
       25 
25 
     | 
    
         
             
              }
         
     | 
| 
       26 
26 
     | 
    
         
             
            ```
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
         @@ -137,9 +137,9 @@ Eager loading is similiar to ActiveRecord's `preload`: each association is loade 
     | 
|
| 
       137 
137 
     | 
    
         
             
            OccamsRecord
         
     | 
| 
       138 
138 
     | 
    
         
             
              .query(q)
         
     | 
| 
       139 
139 
     | 
    
         
             
              .eager_load(:customer)
         
     | 
| 
       140 
     | 
    
         
            -
              .eager_load(:line_items) {
         
     | 
| 
       141 
     | 
    
         
            -
                eager_load(:product)
         
     | 
| 
       142 
     | 
    
         
            -
                eager_load(:something_else)
         
     | 
| 
      
 140 
     | 
    
         
            +
              .eager_load(:line_items) { |l|
         
     | 
| 
      
 141 
     | 
    
         
            +
                l.eager_load(:product)
         
     | 
| 
      
 142 
     | 
    
         
            +
                l.eager_load(:something_else)
         
     | 
| 
       143 
143 
     | 
    
         
             
              }
         
     | 
| 
       144 
144 
     | 
    
         
             
              .find_each { |order|
         
     | 
| 
       145 
145 
     | 
    
         
             
                puts order.customer.name
         
     | 
| 
         @@ -163,11 +163,11 @@ orders = OccamsRecord 
     | 
|
| 
       163 
163 
     | 
    
         | 
| 
       164 
164 
     | 
    
         
             
              # Or use 'scope' to access the full power of ActiveRecord's query builder.
         
     | 
| 
       165 
165 
     | 
    
         
             
              # Here, only 'active' line items will be returned, and in a specific order.
         
     | 
| 
       166 
     | 
    
         
            -
              .eager_load(:line_items) {
         
     | 
| 
       167 
     | 
    
         
            -
                scope { |q| q.active.order("created_at") }
         
     | 
| 
      
 166 
     | 
    
         
            +
              .eager_load(:line_items) { |l|
         
     | 
| 
      
 167 
     | 
    
         
            +
                l.scope { |q| q.active.order("created_at") }
         
     | 
| 
       168 
168 
     | 
    
         | 
| 
       169 
     | 
    
         
            -
                eager_load(:product)
         
     | 
| 
       170 
     | 
    
         
            -
                eager_load(:something_else)
         
     | 
| 
      
 169 
     | 
    
         
            +
                l.eager_load(:product)
         
     | 
| 
      
 170 
     | 
    
         
            +
                l.eager_load(:something_else)
         
     | 
| 
       171 
171 
     | 
    
         
             
              }
         
     | 
| 
       172 
172 
     | 
    
         
             
              .run
         
     | 
| 
       173 
173 
     | 
    
         
             
            ```
         
     | 
| 
         @@ -267,9 +267,9 @@ Let's say we want to load each product with an array of all customers who've ord 
     | 
|
| 
       267 
267 
     | 
    
         
             
            ```ruby
         
     | 
| 
       268 
268 
     | 
    
         
             
            products_with_orders = OccamsRecord
         
     | 
| 
       269 
269 
     | 
    
         
             
              .query(Product.all)
         
     | 
| 
       270 
     | 
    
         
            -
              .eager_load(:line_items) {
         
     | 
| 
       271 
     | 
    
         
            -
                eager_load(:order) {
         
     | 
| 
       272 
     | 
    
         
            -
                  eager_load(:customer)
         
     | 
| 
      
 270 
     | 
    
         
            +
              .eager_load(:line_items) { |l|
         
     | 
| 
      
 271 
     | 
    
         
            +
                l.eager_load(:order) { |l|
         
     | 
| 
      
 272 
     | 
    
         
            +
                  l.eager_load(:customer)
         
     | 
| 
       273 
273 
     | 
    
         
             
                }
         
     | 
| 
       274 
274 
     | 
    
         
             
              }
         
     | 
| 
       275 
275 
     | 
    
         
             
              .map { |product|
         
     | 
| 
         @@ -26,7 +26,13 @@ module OccamsRecord 
     | 
|
| 
       26 
26 
     | 
    
         
             
                    @name, @mapping = name.to_s, mapping
         
     | 
| 
       27 
27 
     | 
    
         
             
                    @sql, @binds, @use, @model = sql, binds, use, model
         
     | 
| 
       28 
28 
     | 
    
         
             
                    @eager_loaders = EagerLoaders::Context.new(@model)
         
     | 
| 
       29 
     | 
    
         
            -
                     
     | 
| 
      
 29 
     | 
    
         
            +
                    if builder
         
     | 
| 
      
 30 
     | 
    
         
            +
                      if builder.arity > 0
         
     | 
| 
      
 31 
     | 
    
         
            +
                        builder.call(self)
         
     | 
| 
      
 32 
     | 
    
         
            +
                      else
         
     | 
| 
      
 33 
     | 
    
         
            +
                        instance_exec(&builder)
         
     | 
| 
      
 34 
     | 
    
         
            +
                      end
         
     | 
| 
      
 35 
     | 
    
         
            +
                    end
         
     | 
| 
       30 
36 
     | 
    
         
             
                  end
         
     | 
| 
       31 
37 
     | 
    
         | 
| 
       32 
38 
     | 
    
         
             
                  #
         
     | 
| 
         @@ -24,7 +24,13 @@ module OccamsRecord 
     | 
|
| 
       24 
24 
     | 
    
         
             
                    @name = (as || ref.name).to_s
         
     | 
| 
       25 
25 
     | 
    
         
             
                    @eager_loaders = EagerLoaders::Context.new(@model)
         
     | 
| 
       26 
26 
     | 
    
         
             
                    @optimizer = optimizer
         
     | 
| 
       27 
     | 
    
         
            -
                     
     | 
| 
      
 27 
     | 
    
         
            +
                    if builder
         
     | 
| 
      
 28 
     | 
    
         
            +
                      if builder.arity > 0
         
     | 
| 
      
 29 
     | 
    
         
            +
                        builder.call(self)
         
     | 
| 
      
 30 
     | 
    
         
            +
                      else
         
     | 
| 
      
 31 
     | 
    
         
            +
                        instance_exec(&builder)
         
     | 
| 
      
 32 
     | 
    
         
            +
                      end
         
     | 
| 
      
 33 
     | 
    
         
            +
                    end
         
     | 
| 
       28 
34 
     | 
    
         
             
                  end
         
     | 
| 
       29 
35 
     | 
    
         | 
| 
       30 
36 
     | 
    
         
             
                  #
         
     | 
| 
         @@ -10,6 +10,12 @@ module OccamsRecord 
     | 
|
| 
       10 
10 
     | 
    
         
             
                  # Specify an association to be eager-loaded. For maximum memory savings, only SELECT the
         
     | 
| 
       11 
11 
     | 
    
         
             
                  # colums you actually need.
         
     | 
| 
       12 
12 
     | 
    
         
             
                  #
         
     | 
| 
      
 13 
     | 
    
         
            +
                  # If you pass a block to nest more eager loads, you may call it with one of two forms: with an argument and without:
         
     | 
| 
      
 14 
     | 
    
         
            +
                  #
         
     | 
| 
      
 15 
     | 
    
         
            +
                  # If you ommit the block argument, the "self" inside the block will be the eager loader. You can call "eager_load" and "scope" directly.
         
     | 
| 
      
 16 
     | 
    
         
            +
                  #
         
     | 
| 
      
 17 
     | 
    
         
            +
                  # If you include the block argument, the "self" inside the block is the same as the self outside the block. The argument will be the eager loader, which you can use to make additional "eager_load" or "scope" calls.
         
     | 
| 
      
 18 
     | 
    
         
            +
                  #
         
     | 
| 
       13 
19 
     | 
    
         
             
                  # @param assoc [Symbol] name of association
         
     | 
| 
       14 
20 
     | 
    
         
             
                  # @param scope [Proc] a scope to apply to the query (optional). It will be passed an
         
     | 
| 
       15 
21 
     | 
    
         
             
                  # ActiveRecord::Relation on which you may call all the normal query hethods (select, where, etc) as well as any scopes you've defined on the model.
         
     | 
| 
         @@ -22,7 +22,13 @@ module OccamsRecord 
     | 
|
| 
       22 
22 
     | 
    
         
             
                    @foreign_type = @ref.foreign_type.to_sym
         
     | 
| 
       23 
23 
     | 
    
         
             
                    @foreign_key = @ref.foreign_key.to_sym
         
     | 
| 
       24 
24 
     | 
    
         
             
                    @eager_loaders = EagerLoaders::Context.new(nil, polymorphic: true)
         
     | 
| 
       25 
     | 
    
         
            -
                     
     | 
| 
      
 25 
     | 
    
         
            +
                    if builder
         
     | 
| 
      
 26 
     | 
    
         
            +
                      if builder.arity > 0
         
     | 
| 
      
 27 
     | 
    
         
            +
                        builder.call(self)
         
     | 
| 
      
 28 
     | 
    
         
            +
                      else
         
     | 
| 
      
 29 
     | 
    
         
            +
                        instance_exec(&builder)
         
     | 
| 
      
 30 
     | 
    
         
            +
                      end
         
     | 
| 
      
 31 
     | 
    
         
            +
                    end
         
     | 
| 
       26 
32 
     | 
    
         
             
                  end
         
     | 
| 
       27 
33 
     | 
    
         | 
| 
       28 
34 
     | 
    
         
             
                  #
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: occams-record
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.6.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Jordan Hollinger
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2023-02- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-02-14 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activerecord
         
     |