4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/selene/component_rules.rb', line 4
def property_rules(component)
{}.tap do |rules|
rules["property %s must not occur more than once"] = lambda do |property, line, message|
invalid = @component.key?(property) && component.class::DISTINCT_PROPERTIES.include?(property)
!invalid.tap { @errors << { :message => message % property } if invalid }
end
rules["properties '%s' and '%s' cannot occur in the same component"] = lambda do |property, line, message|
passed = true
component.class::EXCLUSIVE_PROPERTIES.each do |properties|
other_property = properties.find { |p| @component.key?(p) && p != property }
next unless other_property
passed = false
@errors << { :message => message % [property, other_property] }
end
end
end
end
|