activerecord-locking-symbolic 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/activerecord-locking-symbolic.gemspec +17 -0
- data/lib/activerecord-locking-symbolic.rb +36 -0
- data/lib/activerecord-locking-symbolic/connection_adapters/abstract_adapter.rb +17 -0
- data/lib/activerecord-locking-symbolic/connection_adapters/mysql2_adapter.rb +17 -0
- data/lib/activerecord-locking-symbolic/pessimistic.rb +15 -0
- data/lib/activerecord-locking-symbolic/query_methods.rb +15 -0
- data/lib/activerecord-locking-symbolic/version.rb +7 -0
- metadata +57 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 miio
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Activerecord::Locking::Symbolic
|
2
|
+
|
3
|
+
This is can use lock symbolic option for activerecord
|
4
|
+
|
5
|
+
|
6
|
+
ATTENTION:
|
7
|
+
|
8
|
+
This gem for only MySQL
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'activerecord-locking-symbolic'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install activerecord-locking-symbolic
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Example:
|
27
|
+
|
28
|
+
"FOR UPDATE"
|
29
|
+
|
30
|
+
* Native: Example.find(1, lock: true)
|
31
|
+
* This gem: Example.find(1, lock: :write)
|
32
|
+
|
33
|
+
"LOCK IN SHARE MODE"
|
34
|
+
|
35
|
+
* Native: Example.find(1, lock: "LOCK IN SHARE MODE")
|
36
|
+
* This gem: Example.find(1, lock: :read)
|
37
|
+
|
38
|
+
NOTE: You can use Native lock option.
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/activerecord-locking-symbolic/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["miio"]
|
6
|
+
gem.email = ["info@miio.info"]
|
7
|
+
gem.description = %q{This is can use lock symbolic option for activerecord }
|
8
|
+
gem.summary = %q{This is can use lock symbolic option for activerecord }
|
9
|
+
gem.homepage = "https://github.com/miio/activerecord-locking-symbolic"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "activerecord-locking-symbolic"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ActiveRecord::Locking::Symbolic::VERSION
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext/hash'
|
3
|
+
require 'active_record'
|
4
|
+
require "activerecord-locking-symbolic/version"
|
5
|
+
require "activerecord-locking-symbolic/pessimistic"
|
6
|
+
require "activerecord-locking-symbolic/query_methods"
|
7
|
+
require "activerecord-locking-symbolic/connection_adapters/abstract_adapter"
|
8
|
+
require "activerecord-locking-symbolic/connection_adapters/mysql2_adapter"
|
9
|
+
|
10
|
+
module ActiveRecord
|
11
|
+
module Locking
|
12
|
+
module Symbolic
|
13
|
+
|
14
|
+
if defined?( ::Rails )
|
15
|
+
class Railtie < ::Rails::Railtie
|
16
|
+
def self.apply_activerecord_patch
|
17
|
+
ActiveSupport.on_load(:active_record) do
|
18
|
+
ActiveRecord::Base.send(:include, ActiveRecord::Locking::Symbolic::Pessimistic )
|
19
|
+
ActiveRecord::SpawnMethods.send(:include, ActiveRecord::Locking::Symbolic::QueryMethods )
|
20
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.send( :include, ActiveRecord::Locking::Symbolic::ConnectionAdapters::AbstractAdapter )
|
21
|
+
if defined?( ActiveRecord::ConnectionAdapters::Mysql2Adapter )
|
22
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter.send( :include, ActiveRecord::Locking::Symbolic::ConnectionAdapters::Mysql2Adapter )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
config.after_initialize do
|
28
|
+
self.apply_activerecord_patch
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_record/connection_adapters/abstract_adapter'
|
2
|
+
module ActiveRecord
|
3
|
+
module Locking
|
4
|
+
module Symbolic
|
5
|
+
module ConnectionAdapters
|
6
|
+
module AbstractAdapter
|
7
|
+
def lock_list
|
8
|
+
return {
|
9
|
+
read: true,
|
10
|
+
write: true,
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Locking
|
3
|
+
module Symbolic
|
4
|
+
module ConnectionAdapters
|
5
|
+
module Mysql2Adapter
|
6
|
+
LOCK_LIST = {
|
7
|
+
read: "LOCK IN SHARE MODE",
|
8
|
+
write: true
|
9
|
+
}
|
10
|
+
def lock_list
|
11
|
+
return LOCK_LIST
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Locking
|
3
|
+
module Symbolic
|
4
|
+
module Pessimistic
|
5
|
+
def lock!(lock = true)
|
6
|
+
lock_list = connection.lock_list
|
7
|
+
if lock_list.has_key? lock
|
8
|
+
return super lock_list[lock]
|
9
|
+
end
|
10
|
+
return super lock
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Locking
|
3
|
+
module Symbolic
|
4
|
+
module QueryMethods
|
5
|
+
def lock(lock = true)
|
6
|
+
lock_list = connection.lock_list
|
7
|
+
if lock_list.has_key? lock
|
8
|
+
return super lock_list[lock]
|
9
|
+
end
|
10
|
+
return super lock
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-locking-symbolic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- miio
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-01 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'This is can use lock symbolic option for activerecord '
|
15
|
+
email:
|
16
|
+
- info@miio.info
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- activerecord-locking-symbolic.gemspec
|
27
|
+
- lib/activerecord-locking-symbolic.rb
|
28
|
+
- lib/activerecord-locking-symbolic/connection_adapters/abstract_adapter.rb
|
29
|
+
- lib/activerecord-locking-symbolic/connection_adapters/mysql2_adapter.rb
|
30
|
+
- lib/activerecord-locking-symbolic/pessimistic.rb
|
31
|
+
- lib/activerecord-locking-symbolic/query_methods.rb
|
32
|
+
- lib/activerecord-locking-symbolic/version.rb
|
33
|
+
homepage: https://github.com/miio/activerecord-locking-symbolic
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.11
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: This is can use lock symbolic option for activerecord
|
57
|
+
test_files: []
|