Skip to content

Commit

Permalink
Exposed getChangedFields
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Raede committed Apr 24, 2015
1 parent 94230d4 commit 84368c4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,8 @@ type MyModel struct {

// Easy way to lazy load a diff tracker
func (m *MyModel) GetDiffTracker() *DiffTracker {
v := reflect.ValueOf(m.diffTracker)
if !v.IsValid() || v.IsNil() {
m.diffTracker = NewDiffTracker(m)
if m.diffTracker == nil {
m.diffTracker = bongo.NewDiffTracker(m)
}

return m.diffTracker
Expand Down
6 changes: 3 additions & 3 deletions difftracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (d *DiffTracker) Compare(useBson bool) (bool, []string, error) {
}
}()
if d.original != nil {
diffs, err := getChangedFields(d.original, d.current, useBson)
diffs, err := GetChangedFields(d.original, d.current, useBson)
return false, diffs, err
} else {
return true, []string{}, nil
Expand Down Expand Up @@ -124,7 +124,7 @@ func isNilOrInvalid(f reflect.Value) bool {
return (!f.IsValid())
}

func getChangedFields(struct1 interface{}, struct2 interface{}, useBson bool) ([]string, error) {
func GetChangedFields(struct1 interface{}, struct2 interface{}, useBson bool) ([]string, error) {

diffs := make([]string, 0)
val1 := reflect.ValueOf(struct1)
Expand Down Expand Up @@ -200,7 +200,7 @@ func getChangedFields(struct1 interface{}, struct2 interface{}, useBson bool) ([
diffs = append(diffs, fieldName)
}
} else {
childDiffs, err = getChangedFields(field1.Interface(), field2.Interface(), useBson)
childDiffs, err = GetChangedFields(field1.Interface(), field2.Interface(), useBson)

if err != nil {
return diffs, err
Expand Down
4 changes: 2 additions & 2 deletions difftracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestDiffTracker(t *testing.T) {
Arr: []string{},
}

diffs, err := getChangedFields(foo1, foo2, false)
diffs, err := GetChangedFields(foo1, foo2, false)
So(err, ShouldEqual, nil)
So(len(diffs), ShouldEqual, 2)
So(diffs[0], ShouldEqual, "StringVal")
Expand All @@ -69,7 +69,7 @@ func TestDiffTracker(t *testing.T) {
BarVal: "BAR",
}

diffs, err := getChangedFields(foobar1, foobar2, false)
diffs, err := GetChangedFields(foobar1, foobar2, false)
So(err, ShouldEqual, nil)
So(len(diffs), ShouldEqual, 3)
So(diffs[0], ShouldEqual, "FooVal.IntVal")
Expand Down

0 comments on commit 84368c4

Please sign in to comment.