app/services/change_manager/manager.rb in change_manager-0.0.4 vs app/services/change_manager/manager.rb in change_manager-0.0.5
- old
+ new
@@ -8,16 +8,20 @@
def self.notify(change_id)
puts 'notify method called'
unless Change.find(change_id).cancelled?
change = Change.find(change_id)
- verified_changes = cancel_all_changes(group_similar_changes(change.owner, change.target))
- mailer = ChangeManager::NotificationMailer
- puts 'email sent' if mailer.send_email(mailer.construct_email(verified_changes))
+ verified_changes = process_changes(change)
+ notify_users(verified_changes) unless verified_changes.empty?
end
end
+ private
+ def self.process_changes(change)
+ cancel_all_changes(group_similar_changes(change.owner, change.target))
+ end
+
def self.group_similar_changes(owner, target)
similar_changes = Change.where(owner: owner, target: target, cancelled: false)
if similar_changes.length > 1
cancel_inverse_changes(similar_changes)
end
@@ -40,9 +44,14 @@
def self.cancel_all_changes(verified_changes)
verified_changes.each do |change|
change.cancel
end
verified_changes
+ end
+
+ def self.notify_users(changes)
+ mailer = ChangeManager::NotificationMailer
+ mailer.send_email(mailer.construct_email(changes))
end
end
end