HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //opt/puppetlabs/puppet/lib/ruby/vendor_ruby/mcollective/validator.rb
module MCollective
  module Validator
    @last_load = nil
    @@validator_mutex = Mutex.new

    # Loads the validator plugins. Validators will only be loaded every 5 minutes
    def self.load_validators
      begin
        @@validator_mutex.lock
        if load_validators?
          @last_load = Time.now.to_i
          PluginManager.find_and_load("validator")
        end
      ensure
        @@validator_mutex.unlock
      end
    end

    # Returns and instance of the Plugin class from which objects can be created.
    # Valid plugin names are
    #   :valplugin
    #   "valplugin"
    #   "ValpluginValidator"
    def self.[](klass)
      if klass.is_a?(Symbol)
        klass = validator_class(klass)
      elsif !(klass.match(/.*Validator$/))
        klass = validator_class(klass)
      end

      const_get(klass)
    end

    # Allows validation plugins to be called like module methods : Validator.validate()
    def self.method_missing(method, *args, &block)
      if has_validator?(method)
        validator = Validator[method].validate(*args)
      else
        raise ValidatorError, "Unknown validator: '#{method}'."
      end
    end

    def self.has_validator?(validator)
      const_defined?(validator_class(validator))
    end

    def self.validator_class(validator)
      "#{validator.to_s.capitalize}Validator"
    end

    def self.load_validators?
      return true if @last_load.nil?
      (@last_load - Time.now.to_i) > 300
    end

    # Generic validate method that will call the correct validator
    # plugin based on the type of the validation parameter
    def self.validate(validator, validation)
      Validator.load_validators

      begin
        if [:integer, :boolean, :float, :number, :string].include?(validation)
          Validator.typecheck(validator, validation)

        else
          case validation
            when Regexp,String
              Validator.regex(validator, validation)

            when Symbol
              Validator.send(validation, validator)

            when Array
              Validator.array(validator, validation)

            when Class
              Validator.typecheck(validator, validation)
          end
        end
      rescue => e
        raise ValidatorError, e.to_s
      end
    end
  end
end