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: //proc/thread-self/root/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/mcollective/aggregate/summary.rb
module MCollective
  class Aggregate
    class Summary<Base
      # Before function is run processing
      def startup_hook
        @result[:value] = {}
        @result[:type] = :collection

        # set default aggregate_format if it is undefined
        @aggregate_format = :calculate unless @aggregate_format
      end

      # Increments the value field if value has been seen before
      # Else create a new value field
      def process_result(value, reply)
        unless value.nil?
          if value.is_a? Array
            value.map{|val| add_value(val)}
          else
            add_value(value)
          end
        end
      end

      def add_value(value)
        if @result[:value].keys.include?(value)
          @result[:value][value] += 1
        else
          @result[:value][value] = 1
        end
      end

      def summarize
        if @aggregate_format == :calculate
          max_key_length = @result[:value].keys.map do |k|

            # Response values retain their types. Here we check
            # if the response is a string and turn it into a string
            # if it isn't one.
            if k.respond_to?(:length)
              k.length
            elsif k.respond_to?(:to_s)
              k.to_s.length
            end
          end.max
          @aggregate_format = "%#{max_key_length}s = %s"
        end

        super
      end
    end
  end
end