MMCT TEAM
Server IP : 111.118.215.189  /  Your IP : 18.216.95.250
Web Server : Apache
System : Linux md-in-83.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : a1673wkz ( 2475)
PHP Version : 8.2.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/share/ruby/vendor_ruby/puppet/parser/ast/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/share/ruby/vendor_ruby/puppet/parser/ast/selector.rb
require 'puppet/parser/ast/branch'

class Puppet::Parser::AST
  # The inline conditional operator.  Unlike CaseStatement, which executes
  # code, we just return a value.
  class Selector < AST::Branch
    attr_accessor :param, :values

    def each
      [@param,@values].each { |child| yield child }
    end

    # Find the value that corresponds with the test.
    def evaluate(scope)
      level = scope.ephemeral_level
      # Get our parameter.
      paramvalue = @param.safeevaluate(scope)

      default = nil

      @values = [@values] unless @values.instance_of? AST::ASTArray or @values.instance_of? Array

      # Then look for a match in the options.
      @values.each do |obj|
        # short circuit asap if we have a match
        return obj.value.safeevaluate(scope) if obj.param.evaluate_match(paramvalue, scope)

        # Store the default, in case it's necessary.
        default = obj if obj.param.is_a?(Default)
      end

      # Unless we found something, look for the default.
      return default.value.safeevaluate(scope) if default

      self.fail Puppet::ParseError, "No matching value for selector param '#{paramvalue}'"
    ensure
      scope.unset_ephemeral_var(level)
    end

    def to_s
      if @values.instance_of? AST::ASTArray or @values.instance_of? Array
        v = @values
      else
        v = [@values]
      end

      param.to_s + " ? { " + v.collect { |v| v.to_s }.join(', ') + " }"
    end
  end
end

MMCT - 2023