Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

Added increment and decrement instance methods #13

Closed
wants to merge 1 commit into from

Conversation

gilest
Copy link

@gilest gilest commented Oct 8, 2015

Not sure if anyone else will find this useful but thought it would be worth sharing in just in case.

Behaviour of these methods is almost equivalent to those in ActiveRecord::Persistence.

@ramontayag
Copy link
Contributor

@gilest thanks for the pull request!

I think storext should make it feel, as much as possible, like you're just working with plain database fields. I'm leaning towards monkey-patching increment and decrement instead. That way, you won't have to call a separate storext_(increment|decrement) method. It doesn't seem there's any drawback here if monkey-patched properly. Would you be willing to do this?

@gilest
Copy link
Author

gilest commented Oct 9, 2015

I wondered about doing this myself, but wasn't keen on adding an ActiveRecord monkey-patch in our own project's code. I'd be comfortable doing it within the gem if it's well tested.

This is how I'm actually making use of it right now, something similar could be elevated into the monkey-patched methods.

if self.class.column_names.include?(attribute)
  increment!(attribute)
elsif storext_has_key?(:data, attribute)
  storext_increment!(attribute)
end

I'll see if I can find some time to have a go at it soon.

@ramontayag
Copy link
Contributor

Yes that looks like a good way to go. And I think you're right in not adding it to your own project.

I know the old way was to use alias_method_chain. I am not very familiar with the newer, recommended way: Module#prepend. See rails/rails#19434.

@gilest
Copy link
Author

gilest commented Oct 9, 2015

I've used Module#prepend before. Should be pretty easy to suss.

@ramontayag
Copy link
Contributor

Great. Thanks, @gilest. Let me know if you need assistance.

@ramontayag
Copy link
Contributor

@gilest you probably got busy, so I'll close this. Feel free to re-open when ready.

@ramontayag ramontayag closed this Apr 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants