activerecord-wrap-with-connection 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --colour
3
+ --tty
@@ -0,0 +1,4 @@
1
+ # develop
2
+
3
+ # v0.0.1
4
+ * First release!
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in activerecord-wrap-with-connection.gemspec
4
+ gemspec
5
+
6
+ if RUBY_PLATFORM =~ /darwin/
7
+ gem 'growl_notify'
8
+ gem 'rb-fsevent'
9
+ end
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :version => 2, :cli => '--format documentation' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec/" }
5
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ben Langfeld
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ activerecord-wrap-with-connection
2
+ ===========
3
+
4
+ ActiveRecord is intended for short-lived threads. In order to use it in other situations, connections must be carefully checked back in to the pool in order for it not to be saturated. This gem monkey-patches ActiveRecord to wrap all model methods which touch a connection in [#with_connection](http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html#method-i-with_connection)
5
+
6
+ Requirements
7
+ ------------
8
+
9
+ * Rails 3.0.0+
10
+
11
+ Install
12
+ -------
13
+
14
+ * `gem install activerecord-wrap-with-connection`
15
+ * `require 'activerecord-wrap-with-connection` after requiring ActiveRecord
16
+
17
+ Author
18
+ ------
19
+
20
+ Original author: Ben Langfeld
21
+
22
+ Contributors:
23
+
24
+ * [Steve](http://coderrr.wordpress.com/) - The original version of this patch, for Rails 2.3
25
+
26
+ Links
27
+ -----
28
+ * [Source](https://github.com/adhearsion/activerecord-wrap-with-connection)
29
+ * [Documentation](http://rdoc.info/github/adhearsion/activerecord-wrap-with-connection/master/frames)
30
+ * [Bug Tracker](https://github.com/adhearsion/activerecord-wrap-with-connection/issues)
31
+
32
+ Note on Patches/Pull Requests
33
+ -----------------------------
34
+
35
+ * Fork the project.
36
+ * Make your feature addition or bug fix.
37
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
38
+ * Commit, do not mess with rakefile, version, or history.
39
+ * If you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull
40
+ * Send me a pull request. Bonus points for topic branches.
41
+
42
+ Copyright
43
+ ---------
44
+
45
+ Copyright (c) 2011 Ben Langfeld. MIT licence (see LICENSE for details)
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bones'
3
+ rescue LoadError
4
+ abort '### Please install the "bones" gem ###'
5
+ end
6
+
7
+ require 'bundler/gem_tasks'
8
+
9
+ task :default => :spec
10
+
11
+ require 'rspec/core'
12
+ require 'rspec/core/rake_task'
13
+ require 'ci/reporter/rake/rspec'
14
+ RSpec::Core::RakeTask.new(:spec) do |spec|
15
+ spec.pattern = 'spec/**/*_spec.rb'
16
+ spec.rspec_opts = '--color'
17
+ end
18
+
19
+ task :default => :spec
20
+ task :ci => ['ci:setup:rspec', :spec]
21
+
22
+ require 'yard'
23
+ YARD::Rake::YardocTask.new
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "activerecord-wrap-with-connection/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "activerecord-wrap-with-connection"
7
+ s.version = ActiverecordWrapWithConnection::VERSION
8
+ s.authors = ["Ben Langfeld"]
9
+ s.email = ["ben@langfeld.me"]
10
+ s.homepage = "https://github.com/adhearsion/activerecord-wrap-with-connection"
11
+ s.summary = %q{Using ActiveRecord in long running threads is painful. Here's a nice solution.}
12
+ s.description = %q{Monkey-patches ActiveRecord to wrap all methods which use a database connection with #with_connection}
13
+
14
+ s.rubyforge_project = "activerecord-wrap-with-connection"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency %q<activesupport>, [">= 3.0.0"]
22
+
23
+ s.add_development_dependency %q<bundler>, ["~> 1.0.0"]
24
+ s.add_development_dependency %q<rspec>, [">= 2.5.0"]
25
+ s.add_development_dependency %q<ci_reporter>, [">= 1.6.3"]
26
+ s.add_development_dependency %q<simplecov>, [">= 0"]
27
+ s.add_development_dependency %q<simplecov-rcov>, [">= 0"]
28
+ s.add_development_dependency %q<yard>, ["~> 0.6.0"]
29
+ s.add_development_dependency %q<rake>, [">= 0"]
30
+ s.add_development_dependency %q<mocha>, [">= 0"]
31
+ s.add_development_dependency %q<guard-rspec>
32
+ end
@@ -0,0 +1,28 @@
1
+ require "activerecord-wrap-with-connection/version"
2
+
3
+ {
4
+ (class << ActiveRecord::Base; self; end) => [
5
+ :find, :first, :last, :all, :destroy, :destroy_all, :exists?, :delete, :delete_all, :update, :update_all, :find_each, :find_in_batches, :select, :group, :order, :reorder, :limit, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having, :create_with, :count, :average, :minimum, :maximum, :sum, :calculate, :find_by_sql, :count_by_sql, :quoted_table_name, :reset_sequence_name, :table_exists?, :columns, :quote_value, :sanitize, :quote_bound_value, :encode_quoted_value
6
+ ],
7
+ ActiveRecord::Base => [:create, :quote_value],
8
+ ActiveRecord::Associations::AssociationCollection => [:initialize, :find, :find_target, :load_target, :count, :group, :order, :limit, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having],
9
+ ActiveRecord::Associations::HasAndBelongsToManyAssociation => [:insert_record, :delete_records],
10
+ ActiveRecord::Associations::HasManyThroughAssociation => [:construct_conditions],
11
+ ActiveRecord::Associations::HasOneAssociation => [:construct_sql],
12
+ ActiveRecord::Associations::ClassMethods => [:collection_reader_method, :configure_dependency_for_has_many],
13
+ ActiveRecord::Calculations => [:calculate]
14
+ }.each do |klass, methods|
15
+ methods.each do |method|
16
+ klass.class_eval do
17
+ alias_method_chain method, :connection do |target, punc|
18
+ eval %{
19
+ def #{target}_with_connection#{punc}(*a, &b)
20
+ ActiveRecord::Base.connection_pool.with_connection do
21
+ #{target}_without_connection#{punc}(*a, &b)
22
+ end
23
+ end
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module ActiverecordWrapWithConnection
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiverecordWrapWithConnection do
4
+ end
@@ -0,0 +1,23 @@
1
+ require 'simplecov'
2
+ require 'simplecov-rcov'
3
+ class SimpleCov::Formatter::MergedFormatter
4
+ def format(result)
5
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
6
+ SimpleCov::Formatter::RcovFormatter.new.format(result)
7
+ end
8
+ end
9
+ SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
10
+ SimpleCov.start do
11
+ add_filter "/vendor/"
12
+ end
13
+
14
+ require 'activerecord-wrap-with-connection'
15
+ require 'mocha'
16
+
17
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
18
+
19
+ RSpec.configure do |config|
20
+ config.mock_with :mocha
21
+ config.filter_run :focus => true
22
+ config.run_all_when_everything_filtered = true
23
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-wrap-with-connection
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Langfeld
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-10 00:00:00.000000000 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: &2164658460 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2164658460
26
+ - !ruby/object:Gem::Dependency
27
+ name: bundler
28
+ requirement: &2164644280 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2164644280
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &2164643800 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: 2.5.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2164643800
48
+ - !ruby/object:Gem::Dependency
49
+ name: ci_reporter
50
+ requirement: &2164643320 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 1.6.3
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2164643320
59
+ - !ruby/object:Gem::Dependency
60
+ name: simplecov
61
+ requirement: &2164642760 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2164642760
70
+ - !ruby/object:Gem::Dependency
71
+ name: simplecov-rcov
72
+ requirement: &2164642180 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *2164642180
81
+ - !ruby/object:Gem::Dependency
82
+ name: yard
83
+ requirement: &2164641560 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: 0.6.0
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *2164641560
92
+ - !ruby/object:Gem::Dependency
93
+ name: rake
94
+ requirement: &2164640960 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *2164640960
103
+ - !ruby/object:Gem::Dependency
104
+ name: mocha
105
+ requirement: &2164640380 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: *2164640380
114
+ - !ruby/object:Gem::Dependency
115
+ name: guard-rspec
116
+ requirement: &2164639920 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: *2164639920
125
+ description: ! 'Monkey-patches ActiveRecord to wrap all methods which use a database
126
+ connection with #with_connection'
127
+ email:
128
+ - ben@langfeld.me
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rspec
135
+ - CHANGELOG.md
136
+ - Gemfile
137
+ - Guardfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - activerecord-wrap-with-connection.gemspec
142
+ - lib/activerecord-wrap-with-connection.rb
143
+ - lib/activerecord-wrap-with-connection/version.rb
144
+ - spec/activerecord-wrap-with-connection_spec.rb
145
+ - spec/spec_helper.rb
146
+ has_rdoc: true
147
+ homepage: https://github.com/adhearsion/activerecord-wrap-with-connection
148
+ licenses: []
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project: activerecord-wrap-with-connection
167
+ rubygems_version: 1.6.2
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: Using ActiveRecord in long running threads is painful. Here's a nice solution.
171
+ test_files:
172
+ - spec/activerecord-wrap-with-connection_spec.rb
173
+ - spec/spec_helper.rb