File tree Expand file tree Collapse file tree 5 files changed +9
-23
lines changed
lib/grape/entity/preloader Expand file tree Collapse file tree 5 files changed +9
-23
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -33,21 +33,6 @@ Grape::Entity::Preloader.enabled!
3333#### Local Activation and Deactivation
3434
3535You 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-
5136For 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 33module Grape
44 class Entity
55 class Preloader
6- VERSION = '0.1 .0'
6+ VERSION = '0.2 .0'
77 end
88 end
99end
Original file line number Diff line number Diff line change 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/ )
You can’t perform that action at this time.
0 commit comments