Skip to content

Commit e1a31d8

Browse files
committed
Release version 0.2.0: Remove :grape_entity_preloader option functionality; update README for new usage methods and adjust CHANGELOG.
1 parent a094af0 commit e1a31d8

File tree

5 files changed

+9
-23
lines changed

5 files changed

+9
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## [Unreleased]
22

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+
37
## [0.1.0] - 2025-10-12 UTC
48

59
- Initial release

README.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@ Grape::Entity::Preloader.enabled!
3333
#### Local Activation and Deactivation
3434

3535
You can control preloading for specific `represent` calls.
36-
37-
##### 1. Using options
38-
39-
Pass `grape_entity_preloader: :enabled` or `grape_entity_preloader: :disabled` to the options hash. This overrides the global setting.
40-
41-
```ruby
42-
# Locally enable
43-
MyEntity.represent(users, grape_entity_preloader: :enabled)
44-
45-
# Locally disable
46-
MyEntity.represent(users, grape_entity_preloader: :disabled)
47-
```
48-
49-
##### 2. Using a block
50-
5136
For a specific block of code, you can use `with_enable` or `with_disable`. This is useful in contexts like API endpoints or middlewares.
5237

5338
```ruby

lib/grape/entity/preloader/entity.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ module ClassMethods # rubocop:disable Style/Documentation
1010
def represent(objects, options = {})
1111
options = Grape::Entity::Options.new(options) unless options.is_a?(Grape::Entity::Options)
1212

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) }
1815
end
1916
end
2017
end

lib/grape/entity/preloader/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Grape
44
class Entity
55
class Preloader
6-
VERSION = '0.1.0'
6+
VERSION = '0.2.0'
77
end
88
end
99
end

spec/n_plus_one_op_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@
121121
}
122122

123123
expect do
124-
User::Entity.represent(users, options.dup)
124+
User::Entity.represent(users, options)
125125
end.to make_database_queries(count: 1)
126126
.and make_database_queries(count: 1, matching: /user_books_by_association/)
127127

128128
users.map(&:reload)
129129

130130
options[:only] << { books_by_association: [:tags_by_association] }
131131
expect do
132-
User::Entity.represent(users, options.dup)
132+
User::Entity.represent(users, options)
133133
end.to make_database_queries(count: 2)
134134
.and make_database_queries(count: 1, matching: /user_books_by_association/)
135135
.and make_database_queries(count: 1, matching: /book_tags_by_association/)

0 commit comments

Comments
 (0)