@@ -32,7 +32,7 @@ def valid?(entity)
32
32
33
33
def value ( entity , options )
34
34
new_options = nesting_options_for ( options )
35
- output = OutputBuilder . new
35
+ output = OutputBuilder . new ( entity )
36
36
37
37
normalized_exposures ( entity , new_options ) . each_with_object ( output ) do |exposure , out |
38
38
exposure . with_attr_path ( entity , new_options ) do
@@ -46,7 +46,7 @@ def valid_value_for(key, entity, options)
46
46
new_options = nesting_options_for ( options )
47
47
48
48
result = nil
49
- normalized_exposures ( entity , new_options ) . select { |e | e . key == key } . each do |exposure |
49
+ normalized_exposures ( entity , new_options ) . select { |e | e . key ( entity ) == key } . each do |exposure |
50
50
exposure . with_attr_path ( entity , new_options ) do
51
51
result = exposure . valid_value ( entity , new_options )
52
52
end
@@ -56,7 +56,7 @@ def valid_value_for(key, entity, options)
56
56
57
57
def serializable_value ( entity , options )
58
58
new_options = nesting_options_for ( options )
59
- output = OutputBuilder . new
59
+ output = OutputBuilder . new ( entity )
60
60
61
61
normalized_exposures ( entity , new_options ) . each_with_object ( output ) do |exposure , out |
62
62
exposure . with_attr_path ( entity , new_options ) do
@@ -67,9 +67,9 @@ def serializable_value(entity, options)
67
67
end
68
68
69
69
# if we have any nesting exposures with the same name.
70
- # delegate :deep_complex_nesting?, to: :nested_exposures
71
- def deep_complex_nesting?
72
- nested_exposures . deep_complex_nesting?
70
+ # delegate :deep_complex_nesting?(entity) , to: :nested_exposures
71
+ def deep_complex_nesting? ( entity )
72
+ nested_exposures . deep_complex_nesting? ( entity )
73
73
end
74
74
75
75
private
@@ -92,15 +92,15 @@ def easy_normalized_exposures(entity, options)
92
92
93
93
# This method 'merges' subsequent nesting exposures with the same name if it's needed
94
94
def normalized_exposures ( entity , options )
95
- return easy_normalized_exposures ( entity , options ) unless deep_complex_nesting? # optimization
95
+ return easy_normalized_exposures ( entity , options ) unless deep_complex_nesting? ( entity ) # optimization
96
96
97
97
table = nested_exposures . each_with_object ( { } ) do |exposure , output |
98
98
should_expose = exposure . with_attr_path ( entity , options ) do
99
99
exposure . should_expose? ( entity , options )
100
100
end
101
101
next unless should_expose
102
- output [ exposure . key ] ||= [ ]
103
- output [ exposure . key ] << exposure
102
+ output [ exposure . key ( entity ) ] ||= [ ]
103
+ output [ exposure . key ( entity ) ] << exposure
104
104
end
105
105
table . map do |key , exposures |
106
106
last_exposure = exposures . last
@@ -113,7 +113,9 @@ def normalized_exposures(entity, options)
113
113
end
114
114
new_nested_exposures = nesting_tail . flat_map ( &:nested_exposures )
115
115
NestingExposure . new ( key , { } , [ ] , new_nested_exposures ) . tap do |new_exposure |
116
- new_exposure . instance_variable_set ( :@deep_complex_nesting , true ) if nesting_tail . any? ( &:deep_complex_nesting? )
116
+ if nesting_tail . any? { |exposure | exposure . deep_complex_nesting? ( entity ) }
117
+ new_exposure . instance_variable_set ( :@deep_complex_nesting , true )
118
+ end
117
119
end
118
120
else
119
121
last_exposure
0 commit comments