Add recipients and documents to hash only when changed

This commit is contained in:
Guillaume Dott 2016-07-26 14:55:14 +02:00
parent d6b66ff5ce
commit bec3c8ea85
2 changed files with 13 additions and 4 deletions

View File

@ -94,10 +94,13 @@ module Docurest
emailSubject: emailSubject, emailSubject: emailSubject,
emailBlurb: emailBlurb, emailBlurb: emailBlurb,
emailSettings: emailSettings.to_h, emailSettings: emailSettings.to_h,
documents: documents.map(&:to_h), }.tap do |hash|
recipients: Docurest::Base.hash_by_type(recipients), if documents_changed?
files: files, hash[:documents] = documents.map(&:to_h)
} hash[:files] = files
end
hash[:recipients] = Docurest::Base.hash_by_type(recipients) if recipients_changed?
end
end end
private private

View File

@ -45,8 +45,14 @@ module Docurest
value.send("#{parent_field}=", guid) if parent_field value.send("#{parent_field}=", guid) if parent_field
value.id = values.length + 1 unless value.id value.id = values.length + 1 unless value.id
instance_variable_set(:"@#{klass}_changed", true)
values << value values << value
end end
define_method("#{klass}_changed?") do
!!instance_variable_get(:"@#{klass}_changed")
end
end end
end end
end end