Sha256: d5e59ca5b6169358f3f89b73a04a173945f5a49ffa68dad6d11d91a585ca02b8

Contents?: true

Size: 1.6 KB

Versions: 5

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require "decidim/core"

module Decidim
  module Surveys
    # This is the engine that runs on the public interface of `decidim-surveys`.
    class Engine < ::Rails::Engine
      isolate_namespace Decidim::Surveys

      routes do
        resources :surveys, only: [:show] do
          member do
            post :answer
          end
        end
        root to: "surveys#show"
      end

      initializer "decidim_changes" do
        config.to_prepare do
          Decidim::SettingsChange.subscribe "surveys" do |changes|
            Decidim::Surveys::SettingsChangeJob.perform_later(
              changes[:component_id],
              changes[:previous_settings],
              changes[:current_settings]
            )
          end
        end
      end

      initializer "decidim_surveys.register_metrics" do
        Decidim.metrics_registry.register(:survey_answers) do |metric_registry|
          metric_registry.manager_class = "Decidim::Surveys::Metrics::AnswersMetricManage"

          metric_registry.settings do |settings|
            settings.attribute :highlighted, type: :boolean, default: false
            settings.attribute :scopes, type: :array, default: %w(participatory_process)
            settings.attribute :weight, type: :integer, default: 5
            settings.attribute :stat_block, type: :string, default: "small"
          end
        end

        Decidim.metrics_operation.register(:participants, :surveys) do |metric_operation|
          metric_operation.manager_class = "Decidim::Surveys::Metrics::SurveyParticipantsMetricMeasure"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decidim-surveys-0.25.0 lib/decidim/surveys/engine.rb
decidim-surveys-0.25.0.rc4 lib/decidim/surveys/engine.rb
decidim-surveys-0.25.0.rc3 lib/decidim/surveys/engine.rb
decidim-surveys-0.25.0.rc2 lib/decidim/surveys/engine.rb
decidim-surveys-0.25.0.rc1 lib/decidim/surveys/engine.rb