about summary refs log tree commit diff
path: root/app/lib/admin/metrics/dimension.rb
blob: d8392ddfccff4110861ca90991c2161be97dec21 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

class Admin::Metrics::Dimension
  DIMENSIONS = {
    languages: Admin::Metrics::Dimension::LanguagesDimension,
    sources: Admin::Metrics::Dimension::SourcesDimension,
    servers: Admin::Metrics::Dimension::ServersDimension,
    space_usage: Admin::Metrics::Dimension::SpaceUsageDimension,
    software_versions: Admin::Metrics::Dimension::SoftwareVersionsDimension,
    tag_servers: Admin::Metrics::Dimension::TagServersDimension,
    tag_languages: Admin::Metrics::Dimension::TagLanguagesDimension,
  }.freeze

  def self.retrieve(dimension_keys, start_at, end_at, limit, params)
    Array(dimension_keys).map do |key|
      klass = DIMENSIONS[key.to_sym]
      klass&.new(start_at, end_at, limit, klass.with_params? ? params.require(key.to_sym) : nil)
    end.compact
  end
end