mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-27 14:37:35 +08:00
28 lines
709 B
Ruby
28 lines
709 B
Ruby
# frozen_string_literal: true
|
|
|
|
module ObservableModel
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
after_create :notify_observers_on_create
|
|
after_update :notify_observers_on_update
|
|
end
|
|
|
|
private
|
|
|
|
def changed_by
|
|
last_modified_by || created_by
|
|
end
|
|
|
|
def notify_observers_on_create
|
|
return if Current.team.blank?
|
|
|
|
Extends::TEAM_AUTOMATIONS_OBSERVERS_CONFIG[self.class.base_class.name].each { |observer| observer.constantize.on_create(self, changed_by) }
|
|
end
|
|
|
|
def notify_observers_on_update
|
|
return if Current.team.blank?
|
|
|
|
Extends::TEAM_AUTOMATIONS_OBSERVERS_CONFIG[self.class.base_class.name].each { |observer| observer.constantize.on_update(self, changed_by) }
|
|
end
|
|
end
|