12: def evaluate(scope)
13:
14: [@test1, @test2].each do |t|
15: if t.is_a?(self.class)
16: t.form ||= self.form
17: t.type ||= self.type
18: end
19: end
20:
21:
22: str1, code1 = @test1.safeevaluate scope
23: str2, code2 = @test2.safeevaluate scope
24:
25:
26:
27:
28:
29: code = proc do |resource|
30: case @oper
31: when "and"; code1.call(resource) and code2.call(resource)
32: when "or"; code1.call(resource) or code2.call(resource)
33: when "=="
34: if str1 == "tag"
35: resource.tagged?(str2)
36: else
37: if resource[str1].is_a?(Array)
38: resource[str1].include?(str2)
39: else
40: resource[str1] == str2
41: end
42: end
43: when "!="; resource[str1] != str2
44: end
45: end
46:
47:
48: if self.parens and self.form == :exported
49: Puppet.warning "Parentheses are ignored in Rails searches"
50: end
51:
52: case @oper
53: when "and", "or"
54: if form == :exported
55: raise Puppet::ParseError, "Puppet does not currently support collecting exported resources with more than one condition"
56: end
57: oper = @oper.upcase
58: when "=="; oper = "="
59: else
60: oper = @oper
61: end
62:
63: if oper == "=" or oper == "!="
64:
65: case str1
66: when "title"
67: str = "title #{oper} '#{str2}'"
68: when "tag"
69: str = "puppet_tags.name #{oper} '#{str2}'"
70: else
71: str = "param_values.value #{oper} '#{str2}' and " +
72: "param_names.name = '#{str1}'"
73: end
74: else
75: str = "(%s) %s (%s)" % [str1, oper, str2]
76: end
77:
78: return str, code
79: end