[Bps-public-commit] jifty-plugin-recordhistory branch, master, updated. c80c5b4a2b1a5c0bf0d83e73fe8f2fd6c23fcbd7

Shawn Moore sartak at bestpractical.com
Wed Feb 9 21:13:47 EST 2011


The branch, master has been updated
       via  c80c5b4a2b1a5c0bf0d83e73fe8f2fd6c23fcbd7 (commit)
      from  562ac4d021440224b1382a59ba819670d012dd4c (commit)

Summary of changes:
 .../RecordHistory/Mixin/Model/RecordHistory.pm     |   23 +++++++++++++-------
 1 files changed, 15 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit c80c5b4a2b1a5c0bf0d83e73fe8f2fd6c23fcbd7
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Feb 9 21:13:30 2011 -0500

    Consult the record for a current_change in the set trigger

diff --git a/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm b/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
index 54319c2..5569370 100644
--- a/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
+++ b/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 use base 'Exporter';
 
-our @EXPORT = qw(changes);
+our @EXPORT = qw(changes current_change);
 
 sub import {
     my $class = shift;
@@ -33,13 +33,15 @@ sub import {
             %{ shift @_ },
         );
 
-        # TODO: instead of always creating a change, see if there's an active one
-        my $change = Jifty::Plugin::RecordHistory::Model::Change->new;
-        $change->create(
-            record_class => ref($self),
-            record_id    => $self->id,
-            type         => 'update',
-        );
+        my $change = $self->current_change || do {
+            my $change = Jifty::Plugin::RecordHistory::Model::Change->new;
+            $change->create(
+                record_class => ref($self),
+                record_id    => $self->id,
+                type         => 'update',
+            );
+            $change
+        };
 
         # TODO: capture old_value somehow
         $change->add_change_field(
@@ -85,5 +87,10 @@ sub changes {
     return $changes;
 }
 
+sub current_change {
+    my $self = shift;
+    return $self->{change};
+}
+
 1;
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list