Sha256: 6186fcab5d57a981421df9d5600f351f1aab9bba133e2b26f95d9c88e3047f64

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

module Decidim
  # A Feature represents a self-contained group of functionalities usually
  # defined via a FeatureManifest. It's meant to be able to provide a single
  # feature that spans over several steps.
  class Feature < ApplicationRecord
    include HasSettings
    include Publicable
    include Traceable
    include Loggable

    belongs_to :participatory_space, polymorphic: true

    default_scope { order(arel_table[:weight].asc) }

    delegate :organization, :categories, to: :participatory_space

    def self.log_presenter_class_for(_log)
      Decidim::AdminLog::FeaturePresenter
    end

    # Public: Finds the manifest this feature is associated to.
    #
    # Returns a FeatureManifest.
    def manifest
      Decidim.find_feature_manifest(manifest_name)
    end

    # Public: Assigns a manifest to this feature.
    #
    # manifest - The FeatureManifest for this Feature.
    #
    # Returns nothing.
    def manifest=(manifest)
      self.manifest_name = manifest.name
    end

    # Public: The name of the engine the feature is mounted to.
    def mounted_engine
      "decidim_#{participatory_space_name}_#{manifest_name}"
    end

    # Public: The name of the admin engine the feature is mounted to.
    def mounted_admin_engine
      "decidim_admin_#{participatory_space_name}_#{manifest_name}"
    end

    # Public: The hash of contextual params when the feature is mounted.
    def mounted_params
      {
        host: organization.host,
        feature_id: id,
        "#{participatory_space.underscored_name}_slug".to_sym => participatory_space.slug
      }
    end

    # Public: Returns the value of the registered primary stat.
    def primary_stat
      @primary_stat ||= manifest.stats.filter(primary: true).with_context([self]).map { |name, value| [name, value] }.first&.last
    end

    private

    def participatory_space_name
      participatory_space.underscored_name
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-core-0.10.1 app/models/decidim/feature.rb
decidim-core-0.10.0 app/models/decidim/feature.rb