Sha256: f8267d1db19b8c9233c2077c3c7c20529826704d53caa7e4ce8c362b2dfbc588

Contents?: true

Size: 1.36 KB

Versions: 41

Compression:

Stored size: 1.36 KB

Contents

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

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
choria-mcorpc-support-2.22.1 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-2.22.0 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-2.21.1 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-2.21.0 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-2.20.8 lib/mcollective/aggregate/summary.rb
mcollective-client-2.12.5 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-2.20.7 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-2.20.6 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-2.20.5 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-2.20.4 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-2.20.3 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-2.20.2 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-2.20.0 lib/mcollective/aggregate/summary.rb
choria-mcorpc-support-0.0.1 lib/mcollective/aggregate/summary.rb
mcollective-client-2.12.4 lib/mcollective/aggregate/summary.rb
mcollective-client-2.12.3 lib/mcollective/aggregate/summary.rb
mcollective-client-2.12.1 lib/mcollective/aggregate/summary.rb
mcollective-client-2.12.0 lib/mcollective/aggregate/summary.rb
mcollective-client-2.10.6 lib/mcollective/aggregate/summary.rb
mcollective-client-2.11.4 lib/mcollective/aggregate/summary.rb