grape-entity-preloader 0.1.0 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d32cc4a359717abe3519c7f8bee48d9e35029d1348057a7fa35b043594dd1b5
4
- data.tar.gz: 9ef42ce05db679a5cf7830aeaae698b1557452957648e668ced0ced0cd1e4a3a
3
+ metadata.gz: e1706cb12b11070d46f62c3b3a4e9aacb797e1aff8659ca4c41d2ee68306b5f1
4
+ data.tar.gz: 6a060769e40134c573d14b235def6800b931c1fa8b87e84e5d370ce735384e2b
5
5
  SHA512:
6
- metadata.gz: e9101088f6433f7372ad46b061c34341553259a91a3f903ec1d2dde1112bd2e2d944aec61fcb4ba1ac5ae5828719b3d9eb9dfda88134351e739982e8a8e03149
7
- data.tar.gz: 6d46c749603a41caff0bec514091adc6b630d521c2d0b84aa62f879f76058b4d81185a493f1684eb5f54548290d702462a946cd1c3617af420fd469f16bb023a
6
+ metadata.gz: f17b3f692873737c4e9a55e9a971324b77d8263ff08e62cb3d71bee414487e949fe8e76a6d9b088bf2442c4ce266f11041ae7bd3d0394fb236a635f6a8bbb951
7
+ data.tar.gz: 0e7ba460164dcfad7736f3beb8947c4636d54f954227de6968db5836111171eb8b6b4126fa8348d303f29e15b840e9309c096da04c204a692a434bb419c88cec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2025-10-14 UTC
4
+
5
+ - ⚠️ [Broken] Remove `:grape_entity_preloader` option functionality, please use `Grape::Entity::Preloader.with_enable` or `Grape::Entity::Preloader.with_disable` instead.
6
+
3
7
  ## [0.1.0] - 2025-10-12 UTC
4
8
 
5
9
  - Initial release
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Grape::Entity::Preloader
2
2
 
3
+ [![Ruby](https://github.com/OuYangJinTing/grape-entity-preloader/actions/workflows/main.yml/badge.svg)](https://github.com/OuYangJinTing/grape-entity-preloader/actions/workflows/main.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/grape-entity-preloader.svg?icon=si%3Arubygems&icon_color=%23ff0000)](https://badge.fury.io/rb/grape-entity-preloader)
5
+
3
6
  Grape::Entity::Preloader allows preload associations and callbacks for avoiding N+1 operations in Grape::Entity.
4
7
 
5
8
  ## Installation
@@ -30,21 +33,6 @@ Grape::Entity::Preloader.enabled!
30
33
  #### Local Activation and Deactivation
31
34
 
32
35
  You can control preloading for specific `represent` calls.
33
-
34
- ##### 1. Using options
35
-
36
- Pass `grape_entity_preloader: :enabled` or `grape_entity_preloader: :disabled` to the options hash. This overrides the global setting.
37
-
38
- ```ruby
39
- # Locally enable
40
- MyEntity.represent(users, grape_entity_preloader: :enabled)
41
-
42
- # Locally disable
43
- MyEntity.represent(users, grape_entity_preloader: :disabled)
44
- ```
45
-
46
- ##### 2. Using a block
47
-
48
36
  For a specific block of code, you can use `with_enable` or `with_disable`. This is useful in contexts like API endpoints or middlewares.
49
37
 
50
38
  ```ruby
@@ -10,11 +10,8 @@ module Grape
10
10
  def represent(objects, options = {})
11
11
  options = Grape::Entity::Options.new(options) unless options.is_a?(Grape::Entity::Options)
12
12
 
13
- options[:grape_entity_preloader] ||= Preloader.enabled? ? :enabled : :disabled
14
- Preloader.new(root_exposures, objects, options).call if options[:grape_entity_preloader] == :enabled
15
- options[:grape_entity_preloader] = :finished
16
-
17
- super(objects, options)
13
+ Preloader.new(root_exposures, objects, options).call if Preloader.enabled?
14
+ Preloader.with_disable { super(objects, options) }
18
15
  end
19
16
  end
20
17
  end
@@ -3,7 +3,7 @@
3
3
  module Grape
4
4
  class Entity
5
5
  class Preloader
6
- VERSION = '0.1.0'
6
+ VERSION = '0.2.0'
7
7
  end
8
8
  end
9
9
  end
@@ -121,7 +121,7 @@ RSpec.describe 'N+1 operation' do # rubocop:disable RSpec/DescribeClass
121
121
  }
122
122
 
123
123
  expect do
124
- User::Entity.represent(users, options.dup)
124
+ User::Entity.represent(users, options)
125
125
  end.to make_database_queries(count: 1)
126
126
  .and make_database_queries(count: 1, matching: /user_books_by_association/)
127
127
 
@@ -129,7 +129,7 @@ RSpec.describe 'N+1 operation' do # rubocop:disable RSpec/DescribeClass
129
129
 
130
130
  options[:only] << { books_by_association: [:tags_by_association] }
131
131
  expect do
132
- User::Entity.represent(users, options.dup)
132
+ User::Entity.represent(users, options)
133
133
  end.to make_database_queries(count: 2)
134
134
  .and make_database_queries(count: 1, matching: /user_books_by_association/)
135
135
  .and make_database_queries(count: 1, matching: /book_tags_by_association/)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-entity-preloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OuYangJinTing