@@ -44,18 +44,18 @@ def initialize(name, type: nil, resource: nil, polymorphic: false, primary_key:
44
44
end
45
45
46
46
# @api private
47
- def self . max_depth
48
- @max_depth || 2
47
+ def self . max_recursion
48
+ @max_recursion || 2
49
49
end
50
50
51
51
# Set maximum levels of sideload recursion
52
52
# /authors?comments.authors would be one level
53
53
# /authors?comments.authors.comments.authors would be two levels
54
54
# etc
55
55
#
56
- # Default max depth is 2
57
- def self . max_depth = ( val )
58
- @max_depth = val
56
+ # Default max recursion is 2
57
+ def self . max_recursion = ( val )
58
+ @max_recursion = val
59
59
end
60
60
61
61
# @see #resource_class
@@ -382,17 +382,18 @@ def all_sideloads
382
382
#
383
383
# @return [Hash] The nested include hash
384
384
# @api private
385
- def to_hash ( depth_chain = [ ] , parent = nil )
386
- depth = depth_chain . select { |arr | arr == [ parent , self ] } . length
387
- return { } if depth >= self . class . max_depth
385
+ def to_hash ( recursion_chain = [ ] , parent = nil )
386
+ recursing = -> ( arr ) { arr == [ parent . object_id , self . object_id ] }
387
+ recursions = recursion_chain . select ( &recursing ) . length
388
+ return { } if recursions >= self . class . max_recursion
388
389
389
390
unless ( parent && parent . name == :base ) || name == :base
390
- depth_chain += [ [ parent , self ] ]
391
+ recursion_chain += [ [ parent . object_id , self . object_id ] ]
391
392
end
392
393
393
394
{ name => { } } . tap do |hash |
394
395
all_sideloads . each_pair do |key , sl |
395
- sideload_hash = sl . to_hash ( depth_chain , self )
396
+ sideload_hash = sl . to_hash ( recursion_chain , self )
396
397
hash [ name ] . merge! ( sideload_hash )
397
398
end
398
399
end
0 commit comments