Sha256: 5632ff6ecfe5e42727916241d44044d6a174b9d9a68dd66e8cb4700c17e45fe0

Contents?: true

Size: 1.33 KB

Versions: 88

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Decidim
  # This is a helper class in order to publish component and settings changes
  # so that components can react to these changes and send notifications to users.
  class SettingsChange
    # Publishes a change to ActiveSupport::Notifications.
    #
    # component - The Decidim::Component where the changes have been applied.
    # previous_settings - A Hash or a Decidim::SettingsManifest schema with the settings before changing them.
    # current_settings - A Hash or a Decidim::SettingsManifest schema with the current settings.
    def self.publish(component, previous_settings, current_settings)
      ActiveSupport::Notifications.publish(
        "decidim.settings_change.#{component.manifest_name}",
        component_id: component.id,
        previous_settings: previous_settings.to_h.deep_symbolize_keys,
        current_settings: current_settings.to_h.deep_symbolize_keys
      )
    end

    # Creates a subscription to setting changes.
    #
    # scope - The String manifest name of the component so it only receives relevant changes.
    # block - The block to be executed when an event is received.
    def self.subscribe(scope, &block)
      ActiveSupport::Notifications.subscribe(/^decidim\.settings_change\.#{scope}/) do |_event_name, data|
        block.call(data)
      end
    end
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/services/decidim/settings_change.rb
decidim-core-0.28.4 app/services/decidim/settings_change.rb
decidim-core-0.27.9 app/services/decidim/settings_change.rb
decidim-core-0.29.0 app/services/decidim/settings_change.rb
decidim-core-0.28.3 app/services/decidim/settings_change.rb
decidim-core-0.27.8 app/services/decidim/settings_change.rb
decidim-core-0.29.0.rc4 app/services/decidim/settings_change.rb
decidim-core-0.29.0.rc3 app/services/decidim/settings_change.rb
decidim-core-0.29.0.rc2 app/services/decidim/settings_change.rb
decidim-core-0.29.0.rc1 app/services/decidim/settings_change.rb
decidim-core-0.28.2 app/services/decidim/settings_change.rb
decidim-core-0.27.7 app/services/decidim/settings_change.rb
decidim-core-0.28.1 app/services/decidim/settings_change.rb
decidim-core-0.27.6 app/services/decidim/settings_change.rb
decidim-core-0.26.10 app/services/decidim/settings_change.rb
decidim-core-0.26.9 app/services/decidim/settings_change.rb
decidim-core-0.28.0 app/services/decidim/settings_change.rb
decidim-core-0.27.5 app/services/decidim/settings_change.rb
decidim-core-0.28.0.rc5 app/services/decidim/settings_change.rb
decidim-core-0.28.0.rc4 app/services/decidim/settings_change.rb