@@ -42,37 +42,39 @@ def should_validate?(parameters)
42
42
return false if @optional && ( params ( parameters ) . blank? ||
43
43
any_element_blank? ( parameters ) )
44
44
45
- @dependent_on . each do |dependency |
46
- if dependency . is_a? ( Hash )
47
- dependency_key = dependency . keys [ 0 ]
48
- proc = dependency . values [ 0 ]
49
- return false unless proc . call ( params ( parameters ) . try ( :[] , dependency_key ) )
50
- elsif params ( parameters ) . try ( :[] , dependency ) . blank?
51
- return false
45
+ if @dependent_on && !params ( parameters ) . is_a? ( Array )
46
+ @dependent_on . each do |dependency |
47
+ if dependency . is_a? ( Hash )
48
+ dependency_key = dependency . keys [ 0 ]
49
+ proc = dependency . values [ 0 ]
50
+ return false unless proc . call ( params ( parameters ) . try ( :[] , dependency_key ) )
51
+ elsif params ( parameters ) . try ( :[] , dependency ) . blank?
52
+ return false
53
+ end
52
54
end
53
- end if @dependent_on
55
+ end
54
56
55
57
return true if parent . nil?
56
58
parent . should_validate? ( parameters )
57
59
end
58
60
59
61
# @return [String] the proper attribute name, with nesting considered.
60
- def full_name ( name )
62
+ def full_name ( name , index : nil )
61
63
if nested?
62
64
# Find our containing element's name, and append ours.
63
- " #{ @parent . full_name ( @element ) } #{ array_index } [ #{ name } ]"
65
+ [ @parent . full_name ( @element ) , [ @index || index , name ] . map ( & method ( :brackets ) ) ] . compact . join
64
66
elsif lateral?
65
- # Find the name of the element as if it was at the
66
- # same nesting level as our parent .
67
- @parent . full_name ( name )
67
+ # Find the name of the element as if it was at the same nesting level
68
+ # as our parent. We need to forward our index upward to achieve this .
69
+ @parent . full_name ( name , index : @index )
68
70
else
69
71
# We must be the root scope, so no prefix needed.
70
72
name . to_s
71
73
end
72
74
end
73
75
74
- def array_index
75
- "[#{ @index } ]" if @index . present?
76
+ def brackets ( val )
77
+ "[#{ val } ]" if val
76
78
end
77
79
78
80
# @return [Boolean] whether or not this scope is the root-level scope
@@ -187,7 +189,7 @@ def new_lateral_scope(options, &block)
187
189
element : nil ,
188
190
parent : self ,
189
191
options : @optional ,
190
- type : Hash ,
192
+ type : type == Array ? Array : Hash ,
191
193
dependent_on : options [ :dependent_on ] ,
192
194
&block
193
195
)
0 commit comments