lib/sequel/plugins/bitemporal.rb in sequel_bitemporal-0.4.6 vs lib/sequel/plugins/bitemporal.rb in sequel_bitemporal-0.4.7
- old
+ new
@@ -130,19 +130,19 @@
end
end
def attributes=(attributes)
if attributes.delete(:partial_update) && !@pending_version && !new? && current_version
- @current_version_values = current_version.values
+ @current_version_values = current_version.values if audited?
current_attributes = current_version.keys.inject({}) do |hash, key|
hash[key] = current_version.send key
hash
end
current_attributes.delete :valid_from
current_attributes.delete :valid_to
attributes = current_attributes.merge attributes
- elsif current_version
+ elsif audited? && !new? && current_version
@current_version_values = current_version.values
end
attributes.delete :id
@pending_version ||= model.version_class.new
pending_version.set attributes
@@ -220,21 +220,21 @@
end
versions_dataset.where(id: expired.collect(&:id)).update expired_at: pending_version.created_at
end
def save_pending_version
- current_values_for_audit = @current_version_values || {}
+ current_values_for_audit = @current_version_values || {} if audited?
pending_version.valid_to ||= Time.utc 9999
success = add_version pending_version
if success
self.class.audit_class.audit(
self,
current_values_for_audit,
pending_version.values,
pending_version.valid_from,
send(self.class.audit_updated_by_method)
) if audited?
- @current_version_values = nil
+ @current_version_values = nil if audited?
@pending_version = nil
end
success
end