@@ -32,7 +32,7 @@ def valid?(entity)
3232
3333 def value ( entity , options )
3434 new_options = nesting_options_for ( options )
35- output = OutputBuilder . new
35+ output = OutputBuilder . new ( entity )
3636
3737 normalized_exposures ( entity , new_options ) . each_with_object ( output ) do |exposure , out |
3838 exposure . with_attr_path ( entity , new_options ) do
@@ -46,7 +46,7 @@ def valid_value_for(key, entity, options)
4646 new_options = nesting_options_for ( options )
4747
4848 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 |
5050 exposure . with_attr_path ( entity , new_options ) do
5151 result = exposure . valid_value ( entity , new_options )
5252 end
@@ -56,7 +56,7 @@ def valid_value_for(key, entity, options)
5656
5757 def serializable_value ( entity , options )
5858 new_options = nesting_options_for ( options )
59- output = OutputBuilder . new
59+ output = OutputBuilder . new ( entity )
6060
6161 normalized_exposures ( entity , new_options ) . each_with_object ( output ) do |exposure , out |
6262 exposure . with_attr_path ( entity , new_options ) do
@@ -67,9 +67,9 @@ def serializable_value(entity, options)
6767 end
6868
6969 # 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 )
7373 end
7474
7575 private
@@ -92,15 +92,15 @@ def easy_normalized_exposures(entity, options)
9292
9393 # This method 'merges' subsequent nesting exposures with the same name if it's needed
9494 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
9696
9797 table = nested_exposures . each_with_object ( { } ) do |exposure , output |
9898 should_expose = exposure . with_attr_path ( entity , options ) do
9999 exposure . should_expose? ( entity , options )
100100 end
101101 next unless should_expose
102- output [ exposure . key ] ||= [ ]
103- output [ exposure . key ] << exposure
102+ output [ exposure . key ( entity ) ] ||= [ ]
103+ output [ exposure . key ( entity ) ] << exposure
104104 end
105105 table . map do |key , exposures |
106106 last_exposure = exposures . last
@@ -113,7 +113,9 @@ def normalized_exposures(entity, options)
113113 end
114114 new_nested_exposures = nesting_tail . flat_map ( &:nested_exposures )
115115 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
117119 end
118120 else
119121 last_exposure
0 commit comments