mysql2_query_filter 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eddceaa4bb301b0edd9da54aa02ac5c6c63d2a5a
4
+ data.tar.gz: 6128f750e17219738c5e348453682b2f52dfef6e
5
+ SHA512:
6
+ metadata.gz: fa64eaf6a34336984da3280ab4621d82c5ed374b1b839e2d8bbe44af7f7a01874e45fbfeae87480bfa062a42a26c6586c95116c6387cf9d3921a2cbae9f26896
7
+ data.tar.gz: 7d03c9729600be3b2a3c54e3432f647d9d99a9b19e470e57ff15f2586935f92bd3df6a7b367bdb9c47f93ef706acd0b2ddcf4d00851b93b1e5d73d68f1426ae8
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ test.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mysql2_query_filter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Genki Sugawara
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,57 @@
1
+ # Mysql2QueryFilter
2
+
3
+ Filtering framework for Mysql2.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mysql2_query_filter'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mysql2_query_filter
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'mysql2_query_filter'
25
+
26
+ class MyFilter < Mysql2QueryFilter::Plugin::Filter
27
+ def filter(sql)
28
+ p sql
29
+ end
30
+ end
31
+
32
+ Mysql2QueryFilter.configure do |filter|
33
+ filter.append MyFilter
34
+ end
35
+
36
+ Mysql2QueryFilter.enable
37
+
38
+ client = Mysql2::Client.new(host: 'localhost', username: 'root')
39
+ client.query('show databases')
40
+ ```
41
+
42
+ ### Use plug-in
43
+
44
+ see [mysql2_query_filter-plugin-log](https://github.com/winebarrel/mysql2_query_filter-plugin-log).
45
+
46
+ ```ruby
47
+ require 'mysql2_query_filter'
48
+
49
+ Mysql2QueryFilter.configure do |filter|
50
+ filter.plugin :log #, out: $stderr
51
+ end
52
+
53
+ Mysql2QueryFilter.enable
54
+
55
+ client = Mysql2::Client.new(host: 'localhost', username: 'root')
56
+ client.query('show databases')
57
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,38 @@
1
+ require 'mysql2'
2
+
3
+ require 'mysql2_query_filter/version'
4
+
5
+ require 'mysql2_query_filter/mysql2_client_ext'
6
+ require 'mysql2_query_filter/plugin'
7
+ require 'mysql2_query_filter/plugin/filter'
8
+ require 'mysql2_query_filter/plugins'
9
+ require 'mysql2_query_filter/query_filter'
10
+
11
+ Mysql2::Client.class_eval do
12
+ include Mysql2QueryFilter::Mysql2ClientExt
13
+ end
14
+
15
+ module Mysql2QueryFilter
16
+ @@query_filter = Mysql2QueryFilter::QueryFilter.new
17
+ @@enabled = false
18
+
19
+ def self.configure
20
+ yield(@@query_filter)
21
+ end
22
+
23
+ def self.filter(sql)
24
+ @@query_filter.filter(sql) if @@enabled
25
+ end
26
+
27
+ def self.enable
28
+ @@enabled = true
29
+ end
30
+
31
+ def self.disable
32
+ @@enabled = false
33
+ end
34
+
35
+ def self.register(name, klass)
36
+ Mysql2QueryFilter::Plugins.register(name, klass)
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ module Mysql2QueryFilter::Mysql2ClientExt
2
+ def self.included(klass)
3
+ klass.class_eval do
4
+ alias query_without_filter query
5
+
6
+ def query(*args)
7
+ sql = args.first
8
+ Mysql2QueryFilter.filter(sql)
9
+ query_without_filter(*args)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ module Mysql2QueryFilter::Plugin
2
+ end
@@ -0,0 +1,8 @@
1
+ class Mysql2QueryFilter::Plugin::Filter
2
+ def initialize(options)
3
+ @options = options
4
+ end
5
+
6
+ def filter(sql)
7
+ end
8
+ end
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,24 @@
1
+ class Mysql2QueryFilter::QueryFilter
2
+ def initialize
3
+ @filters = []
4
+ end
5
+
6
+ def plugin(name, options = {})
7
+ filter_class = Mysql2QueryFilter::Plugins[name]
8
+ append(filter_class, options)
9
+ end
10
+
11
+ def append(filter_class, options = {})
12
+ unless filter_class < Mysql2QueryFilter::Plugin::Filter
13
+ raise "Invalid plug-in has been appended: #{filter_class}"
14
+ end
15
+
16
+ @filters << filter_class.new(options)
17
+ end
18
+
19
+ def filter(sql)
20
+ @filters.each do |fltr|
21
+ fltr.filter(sql)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Mysql2QueryFilter
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mysql2_query_filter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mysql2_query_filter'
8
+ spec.version = Mysql2QueryFilter::VERSION
9
+ spec.authors = ['Genki Sugawara']
10
+ spec.email = ['sgwr_dts@yahoo.co.jp']
11
+ spec.summary = %q{Filtering framework for Mysql2.}
12
+ spec.description = %q{Filtering framework for Mysql2.}
13
+ spec.homepage = 'https://github.com/winebarrel/mysql2_query_filter'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'mysql2'
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'rake'
24
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mysql2_query_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Genki Sugawara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mysql2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
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
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Filtering framework for Mysql2.
56
+ email:
57
+ - sgwr_dts@yahoo.co.jp
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/mysql2_query_filter.rb
68
+ - lib/mysql2_query_filter/mysql2_client_ext.rb
69
+ - lib/mysql2_query_filter/plugin.rb
70
+ - lib/mysql2_query_filter/plugin/filter.rb
71
+ - lib/mysql2_query_filter/plugins.rb
72
+ - lib/mysql2_query_filter/query_filter.rb
73
+ - lib/mysql2_query_filter/version.rb
74
+ - mysql2_query_filter.gemspec
75
+ homepage: https://github.com/winebarrel/mysql2_query_filter
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.14
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Filtering framework for Mysql2.
99
+ test_files: []