Module: Grape::Entity::Preloader::Options

Extended by:
ActiveSupport::Concern
Defined in:
lib/grape/entity/preloader/options.rb

Overview

rubocop:disable Style/Documentation

Instance Method Summary collapse

Instance Method Details

#mergeObject

Grape-Entity builds new Options objects via merge/reverse_merge (e.g. reverse_merge(collection: true) when representing an array). The default implementation copies opts_hash but drops @for_nesting_cache, so nested Options created during preloading (and their populated PRELOAD_CACHE_KEY caches) are lost before later serialization. Copy the cache so the same nested Options are reused.



19
20
21
# File 'lib/grape/entity/preloader/options.rb', line 19

def merge(...)
  super.tap { |options| options.instance_variable_set(:@for_nesting_cache, @for_nesting_cache.dup) }
end

#reverse_mergeObject

rubocop:disable Layout/EmptyLineBetweenDefs



22
23
24
# File 'lib/grape/entity/preloader/options.rb', line 22

def reverse_merge(...) # rubocop:disable Layout/EmptyLineBetweenDefs
  super.tap { |options| options.instance_variable_set(:@for_nesting_cache, @for_nesting_cache.dup) }
end