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

Read/write attribute directly from @attributes to match ActiveModel #122

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Read/write attribute directly from @attributes to match ActiveModel #122

wants to merge 2 commits into from

Conversation

kainosnoema
Copy link

Resolves #113

This allows overridden getters/setters to be written like ActiveModel getters/setters and call read_attribute and write_attribute to get the raw value from the attributes hash. This previous behavior was unexpected to users bringing existing code from ActiveModel.

The other benefit of this change is that ActiveModel::Dirty can be included and will actually behave properly since it overrides write_attribute, expecting it to be called when a setter is called.

While I feel strongly that this should be fixed, it's a very significant change and should probably accompany a decent version bump. Thoughts?

This allows overridden getters/setters to be written like ActiveModel
getters/setters and call `read_attribute` and `write_attribute` to get
the raw value from the attributes hash. This previous behavior was
unexpected to users bring existing code from ActiveModel.

The other benefit of this change is that `ActiveModel::Dirty` can be
included and will actually behave properly since it overrides
`write_attribute`, expecting it to be called when a setter is called.

Signed-off-by: Evan Owen <kainosnoema@gmail.com>
This more closely matches the behavior of ActiveRecord, further
reducing unexpected behavior for users familiar with AR.

Signed-off-by: Evan Owen <kainosnoema@gmail.com>
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.

Accessing attribute values from a hash rather than a reader method
1 participant