# File lib/puppet/parser/ast/collexpr.rb, line 12
12:   def evaluate(scope)
13:     # Make sure our contained expressions have all the info they need.
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:     # The code is only used for virtual lookups
22:     str1, code1 = @test1.safeevaluate scope
23:     str2, code2 = @test2.safeevaluate scope
24: 
25:     # First build up the virtual code.
26:     # If we're a conjunction operator, then we're calling code.  I did
27:     # some speed comparisons, and it's at least twice as fast doing these
28:     # case statements as doing an eval here.
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:     # Now build up the rails conditions code
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:       # Add the rails association info where necessary
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 param_names.name = '#{str1}'"
72:       end
73:     else
74:       str = "(#{str1}) #{oper} (#{str2})"
75:     end
76: 
77:     return str, code
78:   end