@@ -139,7 +139,9 @@ def self.expose(*args, &block)
139
139
140
140
args . each do |attribute |
141
141
unless @nested_attributes . empty?
142
+ orig_attribute = attribute . to_sym
142
143
attribute = "#{ @nested_attributes . last } __#{ attribute } "
144
+ nested_attribute_names_hash [ attribute . to_sym ] = orig_attribute
143
145
options [ :nested ] = true
144
146
nested_exposures_hash [ @nested_attributes . last . to_sym ] ||= { }
145
147
nested_exposures_hash [ @nested_attributes . last . to_sym ] [ attribute . to_sym ] = options
@@ -175,7 +177,9 @@ def self.with_options(options)
175
177
# are symbolized references to methods on the containing object, the values are
176
178
# the options that were passed into expose.
177
179
def self . exposures
178
- @exposures ||= { }
180
+ return @exposures unless @exposures . nil?
181
+
182
+ @exposures = { }
179
183
180
184
if superclass . respond_to? :exposures
181
185
@exposures = superclass . exposures . merge ( @exposures )
@@ -185,20 +189,39 @@ def self.exposures
185
189
end
186
190
187
191
class << self
192
+ attr_accessor :_nested_attribute_names_hash
188
193
attr_accessor :_nested_exposures_hash
189
194
195
+ def nested_attribute_names_hash
196
+ self . _nested_attribute_names_hash ||= { }
197
+ end
198
+
190
199
def nested_exposures_hash
191
200
self . _nested_exposures_hash ||= { }
192
201
end
193
202
203
+ def nested_attribute_names
204
+ return @nested_attribute_names unless @nested_attribute_names . nil?
205
+
206
+ @nested_attribute_names = { } . merge ( nested_attribute_names_hash )
207
+
208
+ if superclass . respond_to? :nested_attribute_names
209
+ @nested_attribute_names = superclass . nested_attribute_names . deep_merge ( @nested_attribute_names )
210
+ end
211
+
212
+ @nested_attribute_names
213
+ end
214
+
194
215
def nested_exposures
195
- value = nested_exposures_hash
216
+ return @nested_exposures unless @nested_exposures . nil?
217
+
218
+ @nested_exposures = { } . merge ( nested_exposures_hash )
196
219
197
220
if superclass . respond_to? :nested_exposures
198
- value = superclass . nested_exposures . deep_merge ( value )
221
+ @nested_exposures = superclass . nested_exposures . deep_merge ( @nested_exposures )
199
222
end
200
223
201
- value
224
+ @nested_exposures
202
225
end
203
226
end
204
227
@@ -404,7 +427,8 @@ def to_xml(options = {})
404
427
protected
405
428
406
429
def self . name_for ( attribute )
407
- attribute . to_s . split ( '__' ) . last . to_sym
430
+ attribute = attribute . to_sym
431
+ nested_attribute_names [ attribute ] || attribute
408
432
end
409
433
410
434
def self . key_for ( attribute )
@@ -475,7 +499,10 @@ def valid_exposure?(attribute, exposure_options)
475
499
end
476
500
477
501
def conditions_met? ( exposure_options , options )
478
- if_conditions = ( exposure_options [ :if_extras ] || [ ] ) . dup
502
+ if_conditions = [ ]
503
+ unless exposure_options [ :if_extras ] . nil?
504
+ if_conditions . concat ( exposure_options [ :if_extras ] )
505
+ end
479
506
if_conditions << exposure_options [ :if ] unless exposure_options [ :if ] . nil?
480
507
481
508
if_conditions . each do |if_condition |
@@ -486,7 +513,10 @@ def conditions_met?(exposure_options, options)
486
513
end
487
514
end
488
515
489
- unless_conditions = ( exposure_options [ :unless_extras ] || [ ] ) . dup
516
+ unless_conditions = [ ]
517
+ unless exposure_options [ :unless_extras ] . nil?
518
+ unless_conditions . concat ( exposure_options [ :unless_extras ] )
519
+ end
490
520
unless_conditions << exposure_options [ :unless ] unless exposure_options [ :unless ] . nil?
491
521
492
522
unless_conditions . each do |unless_condition |
0 commit comments