Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Dirty Tracking API #57

Open
dnd opened this issue Dec 20, 2016 · 4 comments
Open

Improve Dirty Tracking API #57

dnd opened this issue Dec 20, 2016 · 4 comments

Comments

@dnd
Copy link

dnd commented Dec 20, 2016

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'

@apotonick
Copy link
Owner

column_changes is changes in Disposable, happy to merge what you suggest, @dnd!

@fighella
Copy link

fighella commented Dec 21, 2016 via email

@dnd
Copy link
Author

dnd commented Dec 22, 2016

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.

@apotonick
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants