IncrementWithSql
Provides #increment_with_sql!
and #decrement_with_sql!
for ActiveRecord::Base,
since ActiveRecord's bulti-in non-atomic #increment
and #decrement
methods don't
provide database consistency.
Installation
Add this line to your application's Gemfile:
gem 'increment_with_sql'
And then execute:
$ bundle
Or install it yourself as:
$ gem install increment_with_sql
Usage
It's simple:
class MyModel < ActiveRecord::Base
def increment_counter!
increment_with_sql! :counter
end
def decrement_counter!
decrement_with_sql! :counter
end
end
Contributing
- Fork it ( https://github.com/[my-github-username]/increment_with_sql/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request