Sha256: 67fdfcc38b3a211e8a22463714fd71441557729d7d75a6ba0171c5295371420b

Contents?: true

Size: 656 Bytes

Versions: 1

Compression:

Stored size: 656 Bytes

Contents

require 'active_support/concern'

module ApplicationRecordConcern
  extend ActiveSupport::Concern
  included do
    after_commit :message_ok

    after_rollback :message_ko

    def message_ok
      ActionCable.server.broadcast("messages", { topic: :record, action: detect_action, success: true, record: self})
    end

    def message_ko
      ActionCable.server.broadcast("messages", { topic: :record, action: detect_action, success: false, record: self})
    end

    def detect_action
      return :create if transaction_include_any_action?([:create])
      return :update if transaction_include_any_action?([:update])
      :destroy
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thecore_backend_commons-3.1.0 config/initializers/concern_application_record.rb