bluerabbit / with_lock_version

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WithLockVersion

Build Status

ActiveRecordでlock_versionカラムを使った楽観的ロックをする際に楽になるhelper methodを提供するgemです。

Installation

Add this line to your application's Gemfile:

gem 'with_lock_version'

And then execute:

$ bundle

Or install it yourself as:

$ gem install with_lock_version

Usage

  create_table :orders do |t|
    t.integer :lock_version, default: 1, null: false
    t.timestamps
  end
class Order < ActiveRecord::Base
  with_lock_versionable # required lock_version and timestamp columns 
end
order = Order.find(id)
order.with_lock_version(params[:lock_version]) do
  # something
end

lock_versionが一致しない場合はActiveRecord::StaleObjectErrorをraiseします。

Development

%cp spec/database.yml.sample spec/database.yml
%bundle exec rspec

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bluerabbit/with_lock_version.

License

The gem is available as open source under the terms of the MIT License.

About

License:MIT License


Languages

Language:Ruby 97.2%Language:Shell 2.8%