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 Active Model Dirty API. #16180

Merged
merged 2 commits into from
Jul 15, 2014
Merged

Conversation

rafaelfranca
Copy link
Member

I did some changes on this API:

  • reset_changes becomes clear_changes_information. I believe this new name matches with what it is doing.
  • reset_* is deprecated in favor of restore_*. This will avoid confusion with the deprecated reset_changes.
  • undo_changes is now restore_attributes. To match the behaviour of restore_*.

@dhh @chancancode

…_information

This method name is causing confusion with the `reset_#{attribute}`
methods. While `reset_name` set the value of the name attribute for the
previous value the `reset_changes` only discard the changes and previous
changes.
@sgrif
Copy link
Contributor

sgrif commented Jul 15, 2014

restore_changes feels weird to me, it almost sounds like it's an undo method for the discarding done by clear_changes_information

@@ -215,6 +224,16 @@ def attribute_will_change!(attr)

# Handle <tt>reset_*!</tt> for +method_missing+.
def reset_attribute!(attr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def restore_attribute!(attr)? 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm 🙈

@rafaelfranca
Copy link
Member Author

restore_values then?

@chancancode
Copy link
Member

❤️ 💚 💙 💛 💜

@sgrif
Copy link
Contributor

sgrif commented Jul 15, 2014

restore_changed_values to be explicit, maybe?

@chancancode
Copy link
Member

How about #restore_attributes? It just occurred to me that when using this method, you are not really thinking about the "changes", but thinking that you'd like to restore your attributes to their previous values (just like when you use restore_name).

As a bonus, it could take a list of attributes for when you want to restrict it to just a subset of possibly-changed-or-not attributes (e.g. def restore_price; restore_attributes(:currency, :price_in_cents); end).

Not sure if "attributes" is what you call them in the Active Model layer though.

@chancancode
Copy link
Member

(or restore_changed_attributes, if it's somehow confusing. we already have a changed_attributes so it pairs nicely)

@dhh
Copy link
Member

dhh commented Jul 15, 2014

I like restore_attributes and restore_age. Great symmetry and we bind the term "restore" to specifically deal with the dirty state.

These methods may cause confusion with the `reset_changes` that
behaves differently
of them.

Also rename undo_changes to restore_changes to match this new set of
methods.
@rafaelfranca
Copy link
Member Author

Changed to restore_attributes. Anything else?

@chancancode
Copy link
Member

❤️ :shipit:! I would like to explore the usefulness of expanding restore_attributes to take an arg list of attributes, but we can discuss more and do that separately later 😄

rafaelfranca added a commit that referenced this pull request Jul 15, 2014
Improve Active Model Dirty API.
@rafaelfranca rafaelfranca merged commit 93e09f5 into rails:master Jul 15, 2014
@rafaelfranca rafaelfranca deleted the rm-dirty branch July 15, 2014 21:45
@bogdan
Copy link
Contributor

bogdan commented Jul 19, 2014

good job

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

Successfully merging this pull request may close these issues.

None yet

5 participants