Updated

app/models/concerns/deal_product / event_creator.rb

A
60 lines of codes
4 methods
10.0 complexity/method
3 churn
39.92 complexity
0 duplications
module DealProduct::EventCreator
  1. DealProduct::EventCreator has no descriptive comment
extend ActiveSupport::Concern included do around_create :create_deal_product_and_event around_destroy :destroy_deal_product_and_create_event def destroy_deal_product_and_create_event transaction do create_event_log_destroy yield end end def create_deal_product_and_event transaction do yield create_event_log end end private def create_event_log Event.create!( deal:, kind: 'deal_product_added', done: true, from_me: true, contact: deal.contact, additional_attributes: { product_id: product.id, deal_id: deal.id, product_name: product.name, deal_name: deal.name } ) end def create_event_log_destroy product_name = product.name deal_name = deal.name product_id = product.id deal_id = deal.id Event.create!( deal:, kind: 'deal_product_removed', done: true, from_me: true, contact: deal.contact, additional_attributes: { product_id:, deal_id:, product_name:, deal_name: } ) end end end