disposable
disposable copied to clipboard
Improve Dirty Tracking API
The dirty tracking API could be made much more useful with some additional methods being provided. Taking from Sequel:
#column_changes
{name: ['old', 'new']}
#initial_value(column)
'old'
#initial_values
{name: 'old', amount: 0}
#reset_column(column)
obj.name => 'old'
column_changes
is changes
in Disposable, happy to merge what you suggest, @dnd!
Woohoo Mergy Christmas
On Wed, Dec 21, 2016 at 6:42 PM, Nick Sutterer [email protected] wrote:
column_changes is changes in Disposable, happy to merge what you suggest, @dnd https://github.com/dnd!
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/apotonick/disposable/issues/57#issuecomment-268457284, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH9Yv9qyFxMS2GBAYCdhAJHQrH-cbKQks5rKNhugaJpZM4LRg7V .
I don't think column_changes
is exactly synonymous, as the Sequel version is a hash arrays with old/new values for any changed fields, whereas disposable is a hash of true/false values. I have to take a look at the actual implementation more, because as of right now I haven't been able to take the time to understand how it works.
I think the current implementation will have to change somewhat, in terms of storing the actual changes. Would also be nice to use changes
the same as the sequel implementation instead of having it just be the true/false values, but that would be an API change. Since v2.0 is out now I think that's off the table.
The implementation is super simple: https://github.com/apotonick/disposable/blob/master/lib/disposable/twin/changed.rb#L38
There's Twin#[]
for the original value and _changes
for the new values, only applied when a setter is called.