Module: Disclosure::Notifications

Included in:
Disclosure
Defined in:
lib/disclosure/notifications.rb

Class Method Summary collapse

Class Method Details

.instrument!Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/disclosure/notifications.rb', line 9

def self.instrument!
  Disclosure.configuration.notifier_classes.each do |klass|
    klass.class_eval do
      around_save :notify_disclosure_with_save

      private

      def notify_disclosure_with_save
        # Keep track of the original model to pick up changes properly
        @model_before_save = self

        # Call save, etc.
        yield

        # Send the notification with the original model
        ActiveSupport::Notifications.instrument("disclosure.model_saved", :model => @model_before_save)
      end
    end
  end
end

.subscribe!Object



3
4
5
6
7
# File 'lib/disclosure/notifications.rb', line 3

def self.subscribe!
  ActiveSupport::Notifications.subscribe "disclosure.model_saved" do |name, start, finish, id, payload|
    Disclosure.react_to!(payload[:model])
  end
end