mysql2_query_filter 0.0.7 → 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 +4 -4
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/README.md +4 -1
- data/Rakefile +4 -1
- data/lib/mysql2_query_filter.rb +9 -1
- data/lib/mysql2_query_filter/{plugin/filter.rb → base.rb} +1 -1
- data/lib/mysql2_query_filter/query_filter.rb +5 -1
- data/lib/mysql2_query_filter/version.rb +1 -1
- data/mysql2_query_filter.gemspec +1 -0
- data/spec/mysql2_query_filter/plugin/test_plugin.rb +9 -0
- data/spec/mysql2_query_filter_spec.rb +42 -0
- data/spec/spec_helper.rb +11 -0
- metadata +26 -5
- data/lib/mysql2_query_filter/plugins.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d022676c32d776a551477f215d2cf8497bf1f0c
|
4
|
+
data.tar.gz: 34358b98e6940db5055810320e4d2d477f22bf63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b5a352c96146904d8dfe339957bd2cdbbc1bc07b6b81c829631074d48d56767a351175549d4936a8a9620fce0fc86008c07ec276f7f119f7b35d2a6d087d717
|
7
|
+
data.tar.gz: 66584176d34607f657f8d88268f8d6a3d78f994f4244538a70e068d6210c32793624303aea7fae03ce6b9cbd1885b740cb7a96daf604fbd71fef9eec138fbfd5
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
Filtering framework for [Mysql2](https://github.com/brianmario/mysql2).
|
4
4
|
|
5
|
+
[](http://badge.fury.io/rb/mysql2_query_filter)
|
6
|
+
[](https://travis-ci.org/winebarrel/mysql2_query_filter)
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
@@ -23,7 +26,7 @@ Or install it yourself as:
|
|
23
26
|
```ruby
|
24
27
|
require 'mysql2_query_filter'
|
25
28
|
|
26
|
-
class MyFilter < Mysql2QueryFilter::
|
29
|
+
class MyFilter < Mysql2QueryFilter::Base
|
27
30
|
def filter(sql, query_options)
|
28
31
|
p sql
|
29
32
|
p query_options
|
data/Rakefile
CHANGED
data/lib/mysql2_query_filter.rb
CHANGED
@@ -2,9 +2,9 @@ require 'mysql2'
|
|
2
2
|
|
3
3
|
require 'mysql2_query_filter/version'
|
4
4
|
|
5
|
+
require 'mysql2_query_filter/base'
|
5
6
|
require 'mysql2_query_filter/mysql2_client_ext'
|
6
7
|
require 'mysql2_query_filter/plugin'
|
7
|
-
require 'mysql2_query_filter/plugin/filter'
|
8
8
|
require 'mysql2_query_filter/query_filter'
|
9
9
|
|
10
10
|
Mysql2::Client.class_eval do
|
@@ -30,4 +30,12 @@ module Mysql2QueryFilter
|
|
30
30
|
def self.disable!
|
31
31
|
@@enabled = false
|
32
32
|
end
|
33
|
+
|
34
|
+
def self.disable!
|
35
|
+
@@enabled = false
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.clear!
|
39
|
+
@@query_filter.clear!
|
40
|
+
end
|
33
41
|
end
|
@@ -9,7 +9,7 @@ class Mysql2QueryFilter::QueryFilter
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def add(filter_class, options = {})
|
12
|
-
unless filter_class < Mysql2QueryFilter::
|
12
|
+
unless filter_class < Mysql2QueryFilter::Base
|
13
13
|
raise "Invalid plug-in has been appended: #{filter_class}"
|
14
14
|
end
|
15
15
|
|
@@ -21,4 +21,8 @@ class Mysql2QueryFilter::QueryFilter
|
|
21
21
|
fltr.filter(sql, query_options)
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
def clear!
|
26
|
+
@filters.clear
|
27
|
+
end
|
24
28
|
end
|
data/mysql2_query_filter.gemspec
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
describe Mysql2QueryFilter do
|
2
|
+
let(:client) { Mysql2::Client.new }
|
3
|
+
|
4
|
+
context 'when using filters' do
|
5
|
+
let(:filter1) do
|
6
|
+
Class.new(Mysql2QueryFilter::Base) do
|
7
|
+
def filter(sql, query_options); sql << ' through filter1'; end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:filter2) do
|
12
|
+
Class.new(Mysql2QueryFilter::Base) do
|
13
|
+
def filter(sql, query_options); sql << ' through filter2'; end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
Mysql2QueryFilter.configure do |filter|
|
19
|
+
filter.add filter1
|
20
|
+
filter.add filter2
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it do
|
25
|
+
expect(client).to receive(:query_without_filter).with('select 1 through filter1 through filter2')
|
26
|
+
client.query('select 1')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when using a plug-in' do
|
31
|
+
before do
|
32
|
+
Mysql2QueryFilter.configure do |filter|
|
33
|
+
filter.plugin :test_plugin
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it do
|
38
|
+
expect(client).to receive(:query_without_filter).with('select 1 through plugin')
|
39
|
+
client.query('select 1')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql2_query_filter
|
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
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
55
69
|
description: Filtering framework for Mysql2.
|
56
70
|
email:
|
57
71
|
- sgwr_dts@yahoo.co.jp
|
@@ -60,18 +74,22 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .travis.yml
|
63
79
|
- Gemfile
|
64
80
|
- LICENSE.txt
|
65
81
|
- README.md
|
66
82
|
- Rakefile
|
67
83
|
- lib/mysql2_query_filter.rb
|
84
|
+
- lib/mysql2_query_filter/base.rb
|
68
85
|
- lib/mysql2_query_filter/mysql2_client_ext.rb
|
69
86
|
- lib/mysql2_query_filter/plugin.rb
|
70
|
-
- lib/mysql2_query_filter/plugin/filter.rb
|
71
|
-
- lib/mysql2_query_filter/plugins.rb
|
72
87
|
- lib/mysql2_query_filter/query_filter.rb
|
73
88
|
- lib/mysql2_query_filter/version.rb
|
74
89
|
- mysql2_query_filter.gemspec
|
90
|
+
- spec/mysql2_query_filter/plugin/test_plugin.rb
|
91
|
+
- spec/mysql2_query_filter_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
75
93
|
homepage: https://github.com/winebarrel/mysql2_query_filter
|
76
94
|
licenses:
|
77
95
|
- MIT
|
@@ -96,4 +114,7 @@ rubygems_version: 2.0.14
|
|
96
114
|
signing_key:
|
97
115
|
specification_version: 4
|
98
116
|
summary: Filtering framework for Mysql2.
|
99
|
-
test_files:
|
117
|
+
test_files:
|
118
|
+
- spec/mysql2_query_filter/plugin/test_plugin.rb
|
119
|
+
- spec/mysql2_query_filter_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
class Mysql2QueryFilter::Plugins
|
2
|
-
@@plugins = {}
|
3
|
-
|
4
|
-
def self.register(name, klass)
|
5
|
-
name = name.to_s
|
6
|
-
|
7
|
-
if @@plugins.has_key?(name)
|
8
|
-
raise "Plugin has already been registered: #{name}"
|
9
|
-
end
|
10
|
-
|
11
|
-
@@plugins[name] = klass
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.[](name)
|
15
|
-
name = name.to_s
|
16
|
-
|
17
|
-
require "mysql2_query_filter/plugin/#{name}"
|
18
|
-
|
19
|
-
plugin = @@plugins[name]
|
20
|
-
|
21
|
-
unless plugin
|
22
|
-
raise "Plugin is not found: #{name}"
|
23
|
-
end
|
24
|
-
|
25
|
-
plugin
|
26
|
-
end
|
27
|
-
end
|