Last active
December 2, 2015 17:28
-
-
Save abitdodgy/d3f13598cacb58d4f92d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UpdateDocument | |
def self.call_on_collection(documents, attributes) | |
Document.transaction do | |
documents.map { |document| new(document) }.each { |service| service.call_without_job(attributes) } | |
end.each(&:queue_job) | |
end | |
attr_reader :document | |
def initialize(document) | |
@document = document | |
end | |
def call(params) | |
call_without_job(params) && queue_job | |
end | |
def call_without_job(params) | |
document.update!(params) | |
end | |
def perform(changes) | |
document.create_activity_from_changes!(changes) | |
end | |
def queue_job | |
if document.previous_changes.any? | |
UpdateDocumentJob.perform_later(document, document.changes_for_activity) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment