22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/j2119/node_validator.rb', line 22
def validate_node(node, path, roles, problems)
if !node.is_a?(Hash)
return
end
@parser.find_more_roles(node, roles)
roles.each do |role|
@parser.get_constraints(role).each do |constraint|
if constraint.applies(node, roles)
constraint.check(node, path, problems)
end
end
end
node.each do |name, val|
if !@parser.field_allowed?(roles, name)
problems << "Field \"#{name}\" not allowed in #{path}"
end
child_roles = @parser.find_child_roles(roles, name)
if !child_roles.empty?
validate_node(val, "#{path}.#{name}", child_roles, problems)
end
grandchild_roles = @parser.find_grandchild_roles(roles, name)
if (!grandchild_roles.empty?) && (!@parser.allows_any?(grandchild_roles))
if val.is_a? Hash
val.each do |child_name, child_val|
validate_node(child_val, "#{path}.#{name}.#{child_name}",
grandchild_roles.clone, problems)
end
elsif val.is_a? Array
i = 0
val.each do |member|
validate_node(member, "#{path}.#{name}[#{i}]",
grandchild_roles.clone, problems)
i += 1
end
end
end
end
end
|