Sha256: 03dc43048edef35c95076a2e2d226c1289fb6eebde40fceb5d11307027b9ea2a

Contents?: true

Size: 1.72 KB

Versions: 11

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

module Karafka
  module Web
    module Ui
      module Models
        module Metrics
          # Namespace for models related to presentation of charts
          module Charts
            # Model for formatting aggregated metrics data for charts
            class Aggregated < Lib::HashProxy
              # @param aggregated [Hash] all aggregated for all periods
              # @param period [Symbol] period that we are interested in
              def initialize(aggregated, period)
                @data = aggregated.to_h.fetch(period)
              end

              # @param args [Array<String>] names of aggregated we want to show
              # @return [String] JSON with data about all the charts we were interested in
              def with(*args)
                args
                  .map { |name| [name.to_sym, public_send(name)] }
                  .to_h
                  .to_json
              end

              # @param method_name [String]
              # @param include_private [Boolean]
              def respond_to_missing?(method_name, include_private = false)
                @data.last.last.key?(method_name.to_sym) || super
              end

              # Handles delegation to fetch appropriate historical metrics based on their name
              #
              # @param method_name [String]
              # @param arguments [Array] missing method call arguments
              def method_missing(method_name, *arguments)
                if @data.last.last.key?(method_name.to_sym)
                  @data.map { |a| [a.first, a.last[method_name]] }
                else
                  super
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
karafka-web-0.7.10 lib/karafka/web/ui/models/metrics/charts/aggregated.rb
karafka-web-0.7.9 lib/karafka/web/ui/models/metrics/charts/aggregated.rb
karafka-web-0.7.8 lib/karafka/web/ui/models/metrics/charts/aggregated.rb
karafka-web-0.7.7 lib/karafka/web/ui/models/metrics/charts/aggregated.rb
karafka-web-0.7.6 lib/karafka/web/ui/models/metrics/charts/aggregated.rb
karafka-web-0.7.5 lib/karafka/web/ui/models/metrics/charts/aggregated.rb
karafka-web-0.7.4 lib/karafka/web/ui/models/metrics/charts/aggregated.rb
karafka-web-0.7.3 lib/karafka/web/ui/models/metrics/charts/aggregated.rb
karafka-web-0.7.2 lib/karafka/web/ui/models/metrics/charts/aggregated.rb
karafka-web-0.7.1 lib/karafka/web/ui/models/metrics/charts/aggregated.rb
karafka-web-0.7.0 lib/karafka/web/ui/models/metrics/charts/aggregated.rb