ar_inception 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/.travis.yml +20 -0
- data/Appraisals +19 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +84 -0
- data/TESTING.md +11 -0
- data/ar_inception.gemspec +22 -0
- data/gemfiles/rails_2.gemfile +13 -0
- data/gemfiles/rails_2.gemfile.lock +47 -0
- data/gemfiles/rails_3.gemfile +13 -0
- data/gemfiles/rails_3.gemfile.lock +60 -0
- data/gemfiles/rails_4.gemfile +13 -0
- data/gemfiles/rails_4.gemfile.lock +71 -0
- data/lib/ar_inception.rb +121 -0
- data/lib/ar_inception/version.rb +3 -0
- data/spec/database.yml +24 -0
- data/spec/escape_spec.rb +61 -0
- data/spec/install_spec.rb +15 -0
- data/spec/models.rb +2 -0
- data/spec/schema.rb +5 -0
- data/spec/spec_helper.rb +33 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjE2MTY1ODA0YjU1NDFkOWQyOGFjYTE4NWY5ZjU3ZjE2NDNmZDlhYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDZjMjE4MDM2NDg1YjEyY2FlNDU5MGYzZDRmNmIyOWZkZDNmMTBkOQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmY4M2YyNTFkNzk4MWQ4MTUxMDMzOGRhYTUxMGYyMjI4MzJjMWM1MDg4ZThl
|
10
|
+
YWJjMjVmYzJhYTgzMTQ1YzAwMTE0N2MxNWZjYmFkOWMzOGU5ZTA2ZjU5Zjk2
|
11
|
+
YmU1ZGFkMmYxOWVjOGRjYzdkMDhkMDY4MjIyNjA4YjA0ZDE2MjU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzBiNDFlMzRmMGY3NGRmNjI1NTFlYmExOGI4MGI3ZmUzOTU1M2IxYTIxMjM3
|
14
|
+
NDFhZmFkZWIzYzBhNTRhMzdlYmM0NmE2ZDVmOGEyZjgzNTI0YzgxNjcyMmRj
|
15
|
+
YzIyYzkxZDNlYjA0YzE4YzRmY2Q4NmU2YzU2ZDhkYmZmMjNiOTU=
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
before_script:
|
4
|
+
- mysql -u root -e 'create database ar_inception; grant all privileges on ar_inception.* to "gemtests"@localhost identified by "rsanders";'
|
5
|
+
- bundle exec rake appraisal:install
|
6
|
+
- echo "Ran before_scripts"
|
7
|
+
|
8
|
+
rvm:
|
9
|
+
- 1.9.3
|
10
|
+
- 2.0.0
|
11
|
+
- 2.1.0
|
12
|
+
- 1.8.7
|
13
|
+
- jruby
|
14
|
+
|
15
|
+
|
16
|
+
notifications:
|
17
|
+
email:
|
18
|
+
- robert@zeevex.com
|
19
|
+
|
20
|
+
script: bundle exec rake appraisal spec
|
data/Appraisals
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
unless RUBY_VERSION.match(/^2\./)
|
2
|
+
appraise "rails-2" do
|
3
|
+
gem "activerecord", "2.3.18"
|
4
|
+
gem "activesupport", "2.3.18"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
appraise "rails-3" do
|
9
|
+
gem "activerecord", "3.2.14"
|
10
|
+
gem "activesupport", "3.2.14"
|
11
|
+
end
|
12
|
+
|
13
|
+
# AR 4 doesn't support Ruby 1.8.7
|
14
|
+
unless RUBY_VERSION.match(/^1\.8\./)
|
15
|
+
appraise "rails-4" do
|
16
|
+
gem "activerecord", "4.0.0"
|
17
|
+
gem "activesupport", "4.0.0"
|
18
|
+
end
|
19
|
+
end
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in ar_inception.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'appraisal'
|
7
|
+
|
8
|
+
gem 'activerecord', '~> 3.2.14'
|
9
|
+
gem 'activesupport', '~> 3.2.14'
|
10
|
+
|
11
|
+
gem 'mysql', :platform => :mri
|
12
|
+
|
13
|
+
gem 'jdbc-mysql', :platform => :jruby
|
14
|
+
gem 'activerecord-jdbc-adapter', :platform => :jruby
|
15
|
+
gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Robert Sanders
|
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,37 @@
|
|
1
|
+
# ArInception
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ar_inception'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ar_inception
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Simply surround the block you wish to run at the "base" transaction level like so:
|
22
|
+
|
23
|
+
ActiveRecord::Base.escape_transaction do
|
24
|
+
your.code.here
|
25
|
+
end
|
26
|
+
|
27
|
+
## Build Status
|
28
|
+
|
29
|
+
[](https://travis-ci.org/zeevex/ar_inception)
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'appraisal'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
|
10
|
+
namespace :spec do
|
11
|
+
SPEC_PLATFORMS = ENV.has_key?('SPEC_PLATFORMS') ?
|
12
|
+
ENV['SPEC_PLATFORMS'].split(/ +/) :
|
13
|
+
%w{1.8.7 2.0.0-p247 1.9.3-p448 jruby-1.7.9}
|
14
|
+
|
15
|
+
def _run_commands_with_rbenv(version, commands)
|
16
|
+
Bundler.with_clean_env do
|
17
|
+
system %{bash -c 'eval "$(rbenv init -)" && unset GEM_HOME GEM_PATH RBENV_VERSION && rbenv shell #{version} && } +
|
18
|
+
Array(commands).join(' && ') + "'"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
task :platformdebug do
|
23
|
+
_run_commands_with_rbenv "1.8.7", ["ruby -v", "set"]
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Run on three Rubies"
|
27
|
+
task :platforms do
|
28
|
+
# current = %x[rbenv version | awk '{print $1}']
|
29
|
+
|
30
|
+
fail = false
|
31
|
+
SPEC_PLATFORMS.each do |version|
|
32
|
+
puts "Switching to #{version}"
|
33
|
+
_run_commands_with_rbenv(version, ["ruby -v",
|
34
|
+
"bundle exec rake appraisal spec"])
|
35
|
+
if $?.exitstatus != 0
|
36
|
+
fail = true
|
37
|
+
break
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
exit (fail ? 1 : 0)
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Install gems for all tested rubies'
|
45
|
+
task :platform_setup do
|
46
|
+
SPEC_PLATFORMS.each do |version|
|
47
|
+
puts "Setting up platform #{version}"
|
48
|
+
_run_commands_with_rbenv(version, ["ruby -v",
|
49
|
+
"gem install bundler",
|
50
|
+
"bundle install",
|
51
|
+
"bundle exec rake appraisal:install"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
namespace :oldspec do
|
57
|
+
desc "Run on three Rubies"
|
58
|
+
task :platforms do
|
59
|
+
current = %x{rvm-prompt v}
|
60
|
+
|
61
|
+
fail = false
|
62
|
+
%w{1.9.3 2.0.0 2.1.0}.each do |version|
|
63
|
+
puts "Switching to #{version}"
|
64
|
+
Bundler.with_clean_env do
|
65
|
+
system %{zsh -i -c 'source ~/.rvm/scripts/rvm && rvm #{version} && gem install bundler && bundle install && bundle exec rake spec'}
|
66
|
+
end
|
67
|
+
if $?.exitstatus != 0
|
68
|
+
fail = true
|
69
|
+
break
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
system %{rvm #{current}}
|
74
|
+
|
75
|
+
exit (fail ? 1 : 0)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
task :repl do
|
81
|
+
sh %q{ bundle exec irb -Ilib -r spec/spec_helper }
|
82
|
+
end
|
83
|
+
|
84
|
+
task :default => 'spec'
|
data/TESTING.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
You'll need a mysql database to run the tests. You can create it like
|
2
|
+
so:
|
3
|
+
|
4
|
+
mysql -u root -pYOURPASS -e <<CMDS
|
5
|
+
create database ar_inception;
|
6
|
+
grant all privileges on ar_inception.* to gemtests@localhost identified by 'rsanders';
|
7
|
+
CMDS
|
8
|
+
|
9
|
+
After you do that, just:
|
10
|
+
|
11
|
+
bundle exec rake spec
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ar_inception/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "ar_inception"
|
8
|
+
gem.version = ArInception::VERSION
|
9
|
+
gem.authors = ["Robert Sanders"]
|
10
|
+
gem.email = ["robert@zeevex.com"]
|
11
|
+
gem.description = %q{Extension to ActiveRecord 3.x to provide parallel transaction scopes.}
|
12
|
+
gem.summary = %q{Extension to ActiveRecord 3.x to provide parallel transaction scopes.}
|
13
|
+
gem.homepage = "http://github.com/zeevex/parallel_transaction_scope"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec', '>= 2.9.0'
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal"
|
6
|
+
gem "mysql", :platform=>:mri
|
7
|
+
gem "jdbc-mysql", :platform=>:jruby
|
8
|
+
gem "activerecord-jdbc-adapter", :platform=>:jruby
|
9
|
+
gem "activerecord-jdbcmysql-adapter", :platform=>:jruby
|
10
|
+
gem "activerecord", "2.3.18"
|
11
|
+
gem "activesupport", "2.3.18"
|
12
|
+
|
13
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/Shared/zeevex/src/github/zxgems/ar_inception
|
3
|
+
specs:
|
4
|
+
ar_inception (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activerecord (2.3.18)
|
10
|
+
activesupport (= 2.3.18)
|
11
|
+
activerecord-jdbc-adapter (1.3.6)
|
12
|
+
activerecord (>= 2.2)
|
13
|
+
activerecord-jdbcmysql-adapter (1.3.6)
|
14
|
+
activerecord-jdbc-adapter (~> 1.3.6)
|
15
|
+
jdbc-mysql (>= 5.1.22)
|
16
|
+
activesupport (2.3.18)
|
17
|
+
appraisal (0.5.2)
|
18
|
+
bundler
|
19
|
+
rake
|
20
|
+
diff-lcs (1.2.5)
|
21
|
+
jdbc-mysql (5.1.28)
|
22
|
+
mysql (2.9.1)
|
23
|
+
rake (10.1.1)
|
24
|
+
rspec (2.14.1)
|
25
|
+
rspec-core (~> 2.14.0)
|
26
|
+
rspec-expectations (~> 2.14.0)
|
27
|
+
rspec-mocks (~> 2.14.0)
|
28
|
+
rspec-core (2.14.8)
|
29
|
+
rspec-expectations (2.14.5)
|
30
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
31
|
+
rspec-mocks (2.14.6)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
java
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
activerecord (= 2.3.18)
|
39
|
+
activerecord-jdbc-adapter
|
40
|
+
activerecord-jdbcmysql-adapter
|
41
|
+
activesupport (= 2.3.18)
|
42
|
+
appraisal
|
43
|
+
ar_inception!
|
44
|
+
jdbc-mysql
|
45
|
+
mysql
|
46
|
+
rake
|
47
|
+
rspec (>= 2.9.0)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal"
|
6
|
+
gem "mysql", :platform=>:mri
|
7
|
+
gem "jdbc-mysql", :platform=>:jruby
|
8
|
+
gem "activerecord-jdbc-adapter", :platform=>:jruby
|
9
|
+
gem "activerecord-jdbcmysql-adapter", :platform=>:jruby
|
10
|
+
gem "activerecord", "3.2.14"
|
11
|
+
gem "activesupport", "3.2.14"
|
12
|
+
|
13
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/Shared/zeevex/src/github/zxgems/ar_inception
|
3
|
+
specs:
|
4
|
+
ar_inception (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (3.2.14)
|
10
|
+
activesupport (= 3.2.14)
|
11
|
+
builder (~> 3.0.0)
|
12
|
+
activerecord (3.2.14)
|
13
|
+
activemodel (= 3.2.14)
|
14
|
+
activesupport (= 3.2.14)
|
15
|
+
arel (~> 3.0.2)
|
16
|
+
tzinfo (~> 0.3.29)
|
17
|
+
activerecord-jdbc-adapter (1.3.6)
|
18
|
+
activerecord (>= 2.2)
|
19
|
+
activerecord-jdbcmysql-adapter (1.3.6)
|
20
|
+
activerecord-jdbc-adapter (~> 1.3.6)
|
21
|
+
jdbc-mysql (>= 5.1.22)
|
22
|
+
activesupport (3.2.14)
|
23
|
+
i18n (~> 0.6, >= 0.6.4)
|
24
|
+
multi_json (~> 1.0)
|
25
|
+
appraisal (0.5.2)
|
26
|
+
bundler
|
27
|
+
rake
|
28
|
+
arel (3.0.3)
|
29
|
+
builder (3.0.4)
|
30
|
+
diff-lcs (1.2.5)
|
31
|
+
i18n (0.6.9)
|
32
|
+
jdbc-mysql (5.1.28)
|
33
|
+
multi_json (1.9.0)
|
34
|
+
mysql (2.9.1)
|
35
|
+
rake (10.1.1)
|
36
|
+
rspec (2.14.1)
|
37
|
+
rspec-core (~> 2.14.0)
|
38
|
+
rspec-expectations (~> 2.14.0)
|
39
|
+
rspec-mocks (~> 2.14.0)
|
40
|
+
rspec-core (2.14.8)
|
41
|
+
rspec-expectations (2.14.5)
|
42
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
43
|
+
rspec-mocks (2.14.6)
|
44
|
+
tzinfo (0.3.38)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
java
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
activerecord (= 3.2.14)
|
52
|
+
activerecord-jdbc-adapter
|
53
|
+
activerecord-jdbcmysql-adapter
|
54
|
+
activesupport (= 3.2.14)
|
55
|
+
appraisal
|
56
|
+
ar_inception!
|
57
|
+
jdbc-mysql
|
58
|
+
mysql
|
59
|
+
rake
|
60
|
+
rspec (>= 2.9.0)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal"
|
6
|
+
gem "mysql", :platform=>:mri
|
7
|
+
gem "jdbc-mysql", :platform=>:jruby
|
8
|
+
gem "activerecord-jdbc-adapter", :platform=>:jruby
|
9
|
+
gem "activerecord-jdbcmysql-adapter", :platform=>:jruby
|
10
|
+
gem "activerecord", "4.0.0"
|
11
|
+
gem "activesupport", "4.0.0"
|
12
|
+
|
13
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,71 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/Shared/zeevex/src/github/zxgems/ar_inception
|
3
|
+
specs:
|
4
|
+
ar_inception (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (4.0.0)
|
10
|
+
activesupport (= 4.0.0)
|
11
|
+
builder (~> 3.1.0)
|
12
|
+
activerecord (4.0.0)
|
13
|
+
activemodel (= 4.0.0)
|
14
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
15
|
+
activesupport (= 4.0.0)
|
16
|
+
arel (~> 4.0.0)
|
17
|
+
activerecord-deprecated_finders (1.0.3)
|
18
|
+
activerecord-jdbc-adapter (1.3.6)
|
19
|
+
activerecord (>= 2.2)
|
20
|
+
activerecord-jdbcmysql-adapter (1.3.6)
|
21
|
+
activerecord-jdbc-adapter (~> 1.3.6)
|
22
|
+
jdbc-mysql (>= 5.1.22)
|
23
|
+
activesupport (4.0.0)
|
24
|
+
i18n (~> 0.6, >= 0.6.4)
|
25
|
+
minitest (~> 4.2)
|
26
|
+
multi_json (~> 1.3)
|
27
|
+
thread_safe (~> 0.1)
|
28
|
+
tzinfo (~> 0.3.37)
|
29
|
+
appraisal (0.5.2)
|
30
|
+
bundler
|
31
|
+
rake
|
32
|
+
arel (4.0.2)
|
33
|
+
atomic (1.1.15)
|
34
|
+
atomic (1.1.15-java)
|
35
|
+
builder (3.1.4)
|
36
|
+
diff-lcs (1.2.5)
|
37
|
+
i18n (0.6.9)
|
38
|
+
jdbc-mysql (5.1.28)
|
39
|
+
minitest (4.7.5)
|
40
|
+
multi_json (1.9.0)
|
41
|
+
mysql (2.9.1)
|
42
|
+
rake (10.1.1)
|
43
|
+
rspec (2.14.1)
|
44
|
+
rspec-core (~> 2.14.0)
|
45
|
+
rspec-expectations (~> 2.14.0)
|
46
|
+
rspec-mocks (~> 2.14.0)
|
47
|
+
rspec-core (2.14.8)
|
48
|
+
rspec-expectations (2.14.5)
|
49
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
50
|
+
rspec-mocks (2.14.6)
|
51
|
+
thread_safe (0.2.0)
|
52
|
+
atomic (>= 1.1.7, < 2)
|
53
|
+
thread_safe (0.2.0-java)
|
54
|
+
atomic (>= 1.1.7, < 2)
|
55
|
+
tzinfo (0.3.38)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
java
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
activerecord (= 4.0.0)
|
63
|
+
activerecord-jdbc-adapter
|
64
|
+
activerecord-jdbcmysql-adapter
|
65
|
+
activesupport (= 4.0.0)
|
66
|
+
appraisal
|
67
|
+
ar_inception!
|
68
|
+
jdbc-mysql
|
69
|
+
mysql
|
70
|
+
rake
|
71
|
+
rspec (>= 2.9.0)
|
data/lib/ar_inception.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'ar_inception/version'
|
2
|
+
require 'active_record'
|
3
|
+
require 'active_support/core_ext/module'
|
4
|
+
require 'thread'
|
5
|
+
|
6
|
+
module ArInception
|
7
|
+
MAX_ESCAPE_DEPTH = 10
|
8
|
+
|
9
|
+
def self.install
|
10
|
+
return if ActiveRecord::Base.respond_to?(:escape_transaction)
|
11
|
+
|
12
|
+
#
|
13
|
+
# These changes are only used for the non-threaded implementation
|
14
|
+
#
|
15
|
+
ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
|
16
|
+
|
17
|
+
#
|
18
|
+
# for every nested escape, this is incremented to ensure a
|
19
|
+
# fresh connection. This must be a thread-local because the suffix
|
20
|
+
# is relative to the base per-thread connection. in other words,
|
21
|
+
# the connection_id is a compound key of (thread_id, escape_level)
|
22
|
+
#
|
23
|
+
Thread.current["_connection_id_suffix"] = 0
|
24
|
+
|
25
|
+
#
|
26
|
+
# Increases/decreases "escape count" by the specified amount, usually +/- 1
|
27
|
+
# Returns new escape count.
|
28
|
+
#
|
29
|
+
# May throw an exception if we've escaped too deep or the escape level has
|
30
|
+
# been corrupted somehow
|
31
|
+
#
|
32
|
+
def adjust_escape_suffix(val)
|
33
|
+
res = (Thread.current["_connection_id_suffix"] || 0) + val
|
34
|
+
raise "Decrementing escape suffix below 0" if res < 0
|
35
|
+
raise "Decrementing escape suffix above 10" if res > ArInception::MAX_ESCAPE_DEPTH
|
36
|
+
Thread.current["_connection_id_suffix"] = res
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
#
|
42
|
+
# ConnectionPool uses 'current_connection_id' as a key into a collection of connections.
|
43
|
+
# each thread is intended to have its own
|
44
|
+
#
|
45
|
+
def current_connection_id_with_escape
|
46
|
+
base = current_connection_id_without_escape
|
47
|
+
suffix = Thread.current["_connection_id_suffix"] || 0
|
48
|
+
suffix == 0 ? base : "#{base}-#{suffix}"
|
49
|
+
end
|
50
|
+
|
51
|
+
alias_method_chain :current_connection_id, :escape
|
52
|
+
end
|
53
|
+
|
54
|
+
class << ActiveRecord::Base
|
55
|
+
#
|
56
|
+
# Evaluate the block outside any current ActiveRecord transactional context;
|
57
|
+
# i.e., every DB interaction will be done with a connection that has no
|
58
|
+
# open transactions. This may be the current per-Thread connection or
|
59
|
+
# a freshly allocated one.
|
60
|
+
#
|
61
|
+
# The primary use for this is to commit an update to the database that
|
62
|
+
# will survive a rollback in any currently open transaction.
|
63
|
+
#
|
64
|
+
# This method may block or raise an exception if the connection pool is
|
65
|
+
# exhausted.
|
66
|
+
#
|
67
|
+
#
|
68
|
+
# This implementation does not create new threads, but rather uses a different connection in
|
69
|
+
# the current thread for the duration of the 'escape_transaction' dynamic scope.
|
70
|
+
#
|
71
|
+
# The advantage of this approach is that any code which depends on thread-locals
|
72
|
+
# will still be available
|
73
|
+
#
|
74
|
+
def escape_transaction
|
75
|
+
if connection.open_transactions == 0
|
76
|
+
yield
|
77
|
+
else
|
78
|
+
conn = nil
|
79
|
+
adjusted = nil
|
80
|
+
begin
|
81
|
+
adjusted = connection_pool.adjust_escape_suffix(1)
|
82
|
+
conn = connection
|
83
|
+
yield
|
84
|
+
ensure
|
85
|
+
# return the connection to the pool and
|
86
|
+
ActiveRecord::Base.connection_pool.checkin(conn) if conn
|
87
|
+
connection_pool.adjust_escape_suffix(-1) if adjusted
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
#
|
93
|
+
# Evaluate the block outside any current ActiveRecord transactional context;
|
94
|
+
# i.e., every DB interaction will be done with a connection that has no
|
95
|
+
# open transactions. As this implementation evaluates the block in a
|
96
|
+
# new thread, it will definitely use a different connection from the one
|
97
|
+
# 'current' in the calling code, and any thread-locals accessed in the
|
98
|
+
# dynamic scope will be different (or absent) during the block's evaluation.
|
99
|
+
#
|
100
|
+
# The primary use for this is to commit an update to the database that
|
101
|
+
# will survive a rollback in any currently open transaction.
|
102
|
+
#
|
103
|
+
# This method may block or raise an exception if the connection pool is
|
104
|
+
# exhausted.
|
105
|
+
#
|
106
|
+
def escape_transaction_via_thread
|
107
|
+
Thread.new do
|
108
|
+
begin
|
109
|
+
yield
|
110
|
+
ensure
|
111
|
+
# return this thread's connection to the pool
|
112
|
+
ActiveRecord::Base.clear_active_connections!
|
113
|
+
end
|
114
|
+
end.join
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
ArInception.install
|
data/spec/database.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
mysql:
|
3
|
+
adapter: mysql
|
4
|
+
hostname: localhost
|
5
|
+
username: gemtests
|
6
|
+
password: rsanders
|
7
|
+
database: ar_inception
|
8
|
+
pool: 30
|
9
|
+
|
10
|
+
jdbcmysql:
|
11
|
+
adapter: jdbcmysql
|
12
|
+
hostname: localhost
|
13
|
+
username: gemtests
|
14
|
+
password: rsanders
|
15
|
+
database: ar_inception
|
16
|
+
pool: 30
|
17
|
+
|
18
|
+
postgresql:
|
19
|
+
adapter: postgresql
|
20
|
+
hostname: localhost
|
21
|
+
username: gemtests
|
22
|
+
password: rsanders
|
23
|
+
database: ar_inception
|
24
|
+
pool: 30
|
data/spec/escape_spec.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead.
|
5
|
+
# Then, you can remove it from this and the functional test.
|
6
|
+
|
7
|
+
describe '#escape_transaction' do
|
8
|
+
before do
|
9
|
+
@conn = ActiveRecord::Base.connection
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should use same connection if not in a transaction" do
|
13
|
+
ActiveRecord::Base.escape_transaction do
|
14
|
+
ActiveRecord::Base.connection.should == @conn
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should use a different connection if in a transaction" do
|
19
|
+
Things.transaction do
|
20
|
+
ActiveRecord::Base.escape_transaction do
|
21
|
+
ActiveRecord::Base.connection.should_not == @conn
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should start with open_transactions == 0" do
|
27
|
+
Things.transaction do
|
28
|
+
ActiveRecord::Base.escape_transaction do
|
29
|
+
ActiveRecord::Base.connection.open_transactions.should == 0
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#escape_transaction_via_thread' do
|
36
|
+
before do
|
37
|
+
@conn = ActiveRecord::Base.connection
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should use a different connection if not in a transaction" do
|
41
|
+
ActiveRecord::Base.escape_transaction_via_thread do
|
42
|
+
ActiveRecord::Base.connection.should_not == @conn
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should use a different connection if in a transaction" do
|
47
|
+
Things.transaction do
|
48
|
+
ActiveRecord::Base.escape_transaction_via_thread do
|
49
|
+
ActiveRecord::Base.connection.should_not == @conn
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should start with open_transactions == 0" do
|
55
|
+
Things.transaction do
|
56
|
+
ActiveRecord::Base.escape_transaction_via_thread do
|
57
|
+
ActiveRecord::Base.connection.open_transactions.should == 0
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead.
|
5
|
+
# Then, you can remove it from this and the functional test.
|
6
|
+
|
7
|
+
describe 'installation' do
|
8
|
+
it "should define escape_transaction method" do
|
9
|
+
ActiveRecord::Base.respond_to?(:escape_transaction).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should define escape_transaction_via_thread method" do
|
13
|
+
ActiveRecord::Base.respond_to?(:escape_transaction_via_thread).should be_true
|
14
|
+
end
|
15
|
+
end
|
data/spec/models.rb
ADDED
data/spec/schema.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
$: << File.expand_path(File.dirname(__FILE__) + '../lib')
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'ar_inception'
|
6
|
+
require 'logger'
|
7
|
+
|
8
|
+
require 'active_support'
|
9
|
+
require 'active_record'
|
10
|
+
|
11
|
+
ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'mri'
|
12
|
+
|
13
|
+
# sqlite doesn't support multiple active connections to the same DB
|
14
|
+
ENV['DB'] ||= (ruby_engine == 'jruby' ? 'jdbcmysql' : 'mysql')
|
15
|
+
|
16
|
+
database_yml = File.expand_path('../database.yml', __FILE__)
|
17
|
+
if File.exists?(database_yml)
|
18
|
+
active_record_configuration = YAML.load_file(database_yml)[ENV['DB']]
|
19
|
+
|
20
|
+
ActiveRecord::Base.establish_connection(active_record_configuration)
|
21
|
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
22
|
+
|
23
|
+
ActiveRecord::Base.silence do
|
24
|
+
ActiveRecord::Migration.verbose = false
|
25
|
+
|
26
|
+
load(File.dirname(__FILE__) + '/schema.rb')
|
27
|
+
load(File.dirname(__FILE__) + '/models.rb')
|
28
|
+
end
|
29
|
+
|
30
|
+
else
|
31
|
+
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
|
32
|
+
end
|
33
|
+
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ar_inception
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Sanders
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.9.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.9.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Extension to ActiveRecord 3.x to provide parallel transaction scopes.
|
42
|
+
email:
|
43
|
+
- robert@zeevex.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .travis.yml
|
50
|
+
- Appraisals
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- TESTING.md
|
56
|
+
- ar_inception.gemspec
|
57
|
+
- gemfiles/rails_2.gemfile
|
58
|
+
- gemfiles/rails_2.gemfile.lock
|
59
|
+
- gemfiles/rails_3.gemfile
|
60
|
+
- gemfiles/rails_3.gemfile.lock
|
61
|
+
- gemfiles/rails_4.gemfile
|
62
|
+
- gemfiles/rails_4.gemfile.lock
|
63
|
+
- lib/ar_inception.rb
|
64
|
+
- lib/ar_inception/version.rb
|
65
|
+
- spec/database.yml
|
66
|
+
- spec/escape_spec.rb
|
67
|
+
- spec/install_spec.rb
|
68
|
+
- spec/models.rb
|
69
|
+
- spec/schema.rb
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
homepage: http://github.com/zeevex/parallel_transaction_scope
|
72
|
+
licenses: []
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.1.11
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Extension to ActiveRecord 3.x to provide parallel transaction scopes.
|
94
|
+
test_files:
|
95
|
+
- spec/database.yml
|
96
|
+
- spec/escape_spec.rb
|
97
|
+
- spec/install_spec.rb
|
98
|
+
- spec/models.rb
|
99
|
+
- spec/schema.rb
|
100
|
+
- spec/spec_helper.rb
|