Add recipients and documents to hash only when changed
This commit is contained in:
parent
d6b66ff5ce
commit
bec3c8ea85
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user