activerecord-pedantmysql2-adapter 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -0
- data/activerecord-pedantmysql2-adapter.gemspec +2 -1
- data/lib/pedant_mysql2.rb +13 -0
- data/lib/pedant_mysql2/version.rb +1 -1
- data/spec/adapter_spec.rb +21 -0
- data/spec/spec_helper.rb +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d97c6c15fa963892eb43e540db0991eb1faa0f4
|
4
|
+
data.tar.gz: 126aac6ba50510b2b98019e78ab7a2a7d0b4b1a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94478f4e513f574c69832141987a3c78131a93e20d076aa8cadf78affc2dd17ef237e9dba84a2fc854f8aac24177299d1859182dc99cc3f9a3c9ee3f6a70bb38
|
7
|
+
data.tar.gz: 30a1e65591898dc7dd60352e603386db1a3f16ecbc4b35fbff7fcaa7321cf29a915b61e630264d45c0bfd39e55695bfda1699845a074b732764629dcc821859d
|
data/README.md
CHANGED
@@ -55,6 +55,39 @@ end
|
|
55
55
|
|
56
56
|
```
|
57
57
|
|
58
|
+
If you want to be able to have some queries react silently to MySQL warnings you can
|
59
|
+
do the following:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
|
63
|
+
PedantMysql2.on_warning = lambda do |warning|
|
64
|
+
if PedantMysql2.silence_warnings?
|
65
|
+
# handle the warning a certain way or return
|
66
|
+
else
|
67
|
+
# simply pass the warning to the caller
|
68
|
+
raise warning
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
PedantMysql2.silence_warnings do
|
73
|
+
# perform query that may raise an error you want to stifle
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
## Development
|
78
|
+
|
79
|
+
Setting up the development environment is very straightforward. In order to keep the test
|
80
|
+
as simple as possible we rely on your MySQL database to have a `travis` user and a
|
81
|
+
`pedant_mysql2_test` database.
|
82
|
+
|
83
|
+
You can set this up easily using the following commands as your `root` MySQL user:
|
84
|
+
|
85
|
+
```
|
86
|
+
CREATE USER 'travis'@'localhost';
|
87
|
+
CREATE DATABASE pedant_mysql2_test;
|
88
|
+
GRANT ALL PRIVILEGES ON pedant_mysql2_test.* TO 'travis'@'localhost';
|
89
|
+
```
|
90
|
+
|
58
91
|
## Contributing
|
59
92
|
|
60
93
|
1. Fork it ( http://github.com/Shopify/activerecord-pedantmysql2-adapter/fork )
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_dependency 'mysql2', '>= 0.3.11'
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
24
24
|
spec.add_development_dependency 'rake'
|
25
|
-
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'rspec', '>= 3.0'
|
26
|
+
spec.add_development_dependency 'rspec-its'
|
26
27
|
spec.add_development_dependency 'coveralls'
|
27
28
|
end
|
data/lib/pedant_mysql2.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
module PedantMysql2
|
2
2
|
class << self
|
3
3
|
attr_accessor :on_warning
|
4
|
+
|
5
|
+
def silence_warnings
|
6
|
+
previous_value = Thread.current[:silence_warnings]
|
7
|
+
Thread.current[:silence_warnings] = true
|
8
|
+
yield
|
9
|
+
ensure
|
10
|
+
Thread.current[:silence_warnings] = previous_value
|
11
|
+
end
|
12
|
+
|
13
|
+
def silence_warnings?
|
14
|
+
Thread.current[:silence_warnings]
|
15
|
+
end
|
16
|
+
|
4
17
|
end
|
5
18
|
self.on_warning = lambda{ |*| }
|
6
19
|
end
|
data/spec/adapter_spec.rb
CHANGED
@@ -43,6 +43,27 @@ describe PedantMysql2 do
|
|
43
43
|
}.to raise_error(MysqlWarning)
|
44
44
|
end
|
45
45
|
|
46
|
+
it 'can allow blocks of queries to be silenced' do
|
47
|
+
PedantMysql2.on_warning = lambda do |warning|
|
48
|
+
raise warning unless PedantMysql2.silence_warnings?
|
49
|
+
end
|
50
|
+
expect {
|
51
|
+
PedantMysql2.silence_warnings do
|
52
|
+
expect(PedantMysql2.silence_warnings?).to be true
|
53
|
+
connection.execute('SELECT 1 + "foo"')
|
54
|
+
end
|
55
|
+
}.to_not raise_error
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'restores the old value that was stored in the thread_local silence_warnings' do
|
59
|
+
Thread.current[:silence_warnings] = 'abracadabra'
|
60
|
+
PedantMysql2.silence_warnings do
|
61
|
+
expect(Thread.current[:silence_warnings]).to be true
|
62
|
+
connection.execute('SELECT 1 + "foo"')
|
63
|
+
end
|
64
|
+
expect(Thread.current[:silence_warnings]).to be == 'abracadabra'
|
65
|
+
end
|
66
|
+
|
46
67
|
describe MysqlWarning do
|
47
68
|
|
48
69
|
subject do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-pedantmysql2-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -68,6 +68,20 @@ dependencies:
|
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-its
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|