Sha256: 8953f9a18d4e757c4172621eb2078c2342b64ea9b3dfe6585d576a1fb898eb27
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true module Decidim # This is a helper class in order to publish feature and settings changes # so that components can react to these changes and send notifications to users. class SettingsChange # Publishes a change to ActiveSupport::Notifications. # # feature - The Decidim::Feature 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(feature, previous_settings, current_settings) ActiveSupport::Notifications.publish( "decidim.settings_change.#{feature.manifest_name}", feature_id: feature.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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
decidim-core-0.10.1 | app/services/decidim/settings_change.rb |
decidim-core-0.10.0 | app/services/decidim/settings_change.rb |