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,
emailBlurb: emailBlurb,
emailSettings: emailSettings.to_h,
documents: documents.map(&:to_h),
recipients: Docurest::Base.hash_by_type(recipients),
files: files,
}
}.tap do |hash|
if documents_changed?
hash[:documents] = documents.map(&:to_h)
hash[:files] = files
end
hash[:recipients] = Docurest::Base.hash_by_type(recipients) if recipients_changed?
end
end
private

View File

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