Sha256: 099eefb3016091d2df1ff837c6439c872adf299f9ffa84fc90be8c0c8461132e

Contents?: true

Size: 1.64 KB

Versions: 81

Compression:

Stored size: 1.64 KB

Contents

require 'puppet'
require 'puppet/parser/ast/branch'
require 'puppet/parser/collector'

# An object that collects stored objects from the central cache and returns
# them to the current host, yo.
class Puppet::Parser::AST
class CollExpr < AST::Branch
  attr_accessor :test1, :test2, :oper, :form, :type, :parens

  # We return an object that does a late-binding evaluation.
  def evaluate(scope)
    # Make sure our contained expressions have all the info they need.
    [@test1, @test2].each do |t|
      if t.is_a?(self.class)
        t.form ||= self.form
        t.type ||= self.type
      end
    end

    # The code is only used for virtual lookups
    match1, code1 = @test1.safeevaluate scope
    match2, code2 = @test2.safeevaluate scope

    # First build up the virtual code.
    # If we're a conjunction operator, then we're calling code.  I did
    # some speed comparisons, and it's at least twice as fast doing these
    # case statements as doing an eval here.
    code = proc do |resource|
      case @oper
      when "and"; code1.call(resource) and code2.call(resource)
      when "or"; code1.call(resource) or code2.call(resource)
      when "=="
        if match1 == "tag"
          resource.tagged?(match2)
        else
          if resource[match1].is_a?(Array)
            resource[match1].include?(match2)
          else
            resource[match1] == match2
          end
        end
      when "!="; resource[match1] != match2
      end
    end

    match = [match1, @oper, match2]
    return match, code
  end

  def initialize(hash = {})
    super

    raise ArgumentError, "Invalid operator #{@oper}" unless %w{== != and or}.include?(@oper)
  end
end
end

Version data entries

81 entries across 81 versions & 4 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/parser/ast/collexpr.rb
puppet-parse-0.1.3 lib/vendor/puppet/parser/ast/collexpr.rb
puppet-parse-0.1.2 lib/vendor/puppet/parser/ast/collexpr.rb
puppet-parse-0.1.1 lib/vendor/puppet/parser/ast/collexpr.rb
puppet-2.7.26 lib/puppet/parser/ast/collexpr.rb
puppet-3.4.3 lib/puppet/parser/ast/collexpr.rb
puppet-2.7.25 lib/puppet/parser/ast/collexpr.rb
puppet-3.4.2 lib/puppet/parser/ast/collexpr.rb
puppet-2.7.24 lib/puppet/parser/ast/collexpr.rb
puppet-3.4.1 lib/puppet/parser/ast/collexpr.rb
puppet-3.4.0 lib/puppet/parser/ast/collexpr.rb
puppet-3.4.0.rc2 lib/puppet/parser/ast/collexpr.rb
puppet-3.4.0.rc1 lib/puppet/parser/ast/collexpr.rb
puppet-3.3.2 lib/puppet/parser/ast/collexpr.rb
puppet-3.3.1 lib/puppet/parser/ast/collexpr.rb
puppet-3.3.1.rc3 lib/puppet/parser/ast/collexpr.rb
puppet-3.3.1.rc2 lib/puppet/parser/ast/collexpr.rb
puppet-3.3.1.rc1 lib/puppet/parser/ast/collexpr.rb
puppet-3.3.0 lib/puppet/parser/ast/collexpr.rb
puppet-3.3.0.rc3 lib/puppet/parser/ast/collexpr.rb