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
77
78
79
80
81
|
# File 'lib/element_filter.rb', line 48
def matches?(value)
@matchers.each do |operator, matchers|
matchers.each do |matcher|
values_equal = case value
when Machinery::Array
value_array = value.elements
(value_array - Array(matcher)).empty? && (Array(matcher) - value_array).empty?
when ::Array
(value - Array(matcher)).empty? && (Array(matcher) - value).empty?
when String
if matcher.is_a?(Array)
exception = Machinery::Errors::ElementFilterTypeMismatch.new
exception.failed_matcher =
"#{path}#{operator}#{matcher.join(",")}"
raise exception
end
if matcher.end_with?("*")
value.start_with?(matcher[0..-2])
else
value == matcher
end
end
if operator == Machinery::Filter::OPERATOR_EQUALS
return true if values_equal
elsif operator == Machinery::Filter::OPERATOR_EQUALS_NOT
return true unless values_equal
end
end
end
false
end
|