Sha256: 252f9e718011a2399427bf347a0fdb8cd1d1eef992bed81bf56152e12fa9a93d

Contents?: true

Size: 903 Bytes

Versions: 12

Compression:

Stored size: 903 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # This class acts as a manifest for metrics.
  #
  # This manifest is a simple object that holds and stores currently available
  # metrics and its managers, for calculations purpose
  #
  class MetricManifest
    include ActiveModel::Model
    include Decidim::AttributeObject::Model

    attribute :metric_name, String
    attribute :manager_class, String

    validates :metric_name, :manager_class, presence: true

    def has_settings?
      settings.attributes.any?
    end

    def settings(&block)
      @settings ||= SettingsManifest.new
      yield(@settings) if block
      @settings
    end

    # stat_block is a non-required parameter
    # This method make it easier to retrieve it,
    #  and gives an empty string if it's not configured
    def stat_block
      settings.attributes[:stat_block].try(:[], :default) || ""
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 lib/decidim/metric_manifest.rb
decidim-core-0.27.8 lib/decidim/metric_manifest.rb
decidim-core-0.27.7 lib/decidim/metric_manifest.rb
decidim-core-0.27.6 lib/decidim/metric_manifest.rb
decidim-core-0.27.5 lib/decidim/metric_manifest.rb
decidim-core-0.27.4 lib/decidim/metric_manifest.rb
decidim-core-0.27.3 lib/decidim/metric_manifest.rb
decidim-core-0.27.2 lib/decidim/metric_manifest.rb
decidim-core-0.27.1 lib/decidim/metric_manifest.rb
decidim-core-0.27.0 lib/decidim/metric_manifest.rb
decidim-core-0.27.0.rc2 lib/decidim/metric_manifest.rb
decidim-core-0.27.0.rc1 lib/decidim/metric_manifest.rb