Class: Rails::Contact::MergeContactsService
- Inherits:
-
Object
- Object
- Rails::Contact::MergeContactsService
- Defined in:
- lib/rails/contact/merge_contacts_service.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(source_id:, target_id:) ⇒ MergeContactsService
constructor
A new instance of MergeContactsService.
Constructor Details
#initialize(source_id:, target_id:) ⇒ MergeContactsService
Returns a new instance of MergeContactsService.
6 7 8 9 |
# File 'lib/rails/contact/merge_contacts_service.rb', line 6 def initialize(source_id:, target_id:) @source = Contact.includes(:emails, :phones, :addresses, :websites, :events, :labels).find(source_id) @target = Contact.includes(:emails, :phones, :addresses, :websites, :events, :labels).find(target_id) end |
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rails/contact/merge_contacts_service.rb', line 11 def call raise ArgumentError, "Source and target must be different" if @source.id == @target.id Contact.transaction do merge_scalar_fields merge_nested_records merge_labels @target.save! @source.destroy! end @target end |