resolver_replace 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +19 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -4
- data/lib/resolver_replace.rb +3 -1
- data/lib/resolver_replace/error.rb +3 -0
- data/lib/resolver_replace/plugins/mysql2.rb +12 -11
- data/resolver_replace.gemspec +1 -1
- data/spec/resolver_replace_spec.rb +17 -11
- data/spec/spec_helper.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaf2d6d3e1a9b1b8343440183c70d570a1d0a2c4
|
4
|
+
data.tar.gz: 5d1c057c384ddc95a09b62d08d323d5dec73a5e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9dc86bdb74db1b6fbfff10336f4bb25a36a464153a0974a83e82678b2bddad989da5b9160ea3d64635e4f92938f12a81414aaefba9e23fcbb3b7f8e4b59d940
|
7
|
+
data.tar.gz: 7d4233e457e5448abb47aeec0f242e92c10aff38c0ad36fdf5bd3347641bea99d126a01543a80a43925c76e6b398cc86b8b74df1626ddeb53ccb52d647633488
|
data/.gitignore
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,14 +20,14 @@ This gem works similarly, but allows to replace the resolver with your favorite
|
|
20
20
|
For example, if you want to replace the resolver with `Resolv::DNS`, write as followings:
|
21
21
|
|
22
22
|
```ruby
|
23
|
-
require '
|
24
|
-
require '
|
23
|
+
require 'resolv' # Resolv::DNS
|
24
|
+
require 'resolver_replace' # ResolverReplace
|
25
25
|
|
26
26
|
resolver = Resolv::DNS.new(:nameserver => ['210.251.121.21'],
|
27
27
|
:search => ['ruby-lang.org'],
|
28
28
|
:ndots => 1)
|
29
29
|
|
30
|
-
ResolverReplace.
|
30
|
+
ResolverReplace.register!(
|
31
31
|
getaddress: Proc.new {|host| resolver.getaddress(host) },
|
32
32
|
getaddresses: Proc.new {|host| resolver.getaddresses(host) },
|
33
33
|
error_class: Resolv::ResolvError,
|
@@ -43,7 +43,7 @@ The `mysql2` plugin is available for example. Use as followings:
|
|
43
43
|
|
44
44
|
```ruby
|
45
45
|
ResolverReplace.load_plugin('mysql2')
|
46
|
-
ResolverReplace.
|
46
|
+
ResolverReplace.register!(
|
47
47
|
getaddress: Proc.new {|host| resolver.getaddress(host) },
|
48
48
|
getaddresses: Proc.new {|host| resolver.getaddresses(host) },
|
49
49
|
error_class: Resolv::ResolvError,
|
data/lib/resolver_replace.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'resolver_replace/error'
|
2
|
+
|
1
3
|
class ResolverReplace
|
2
4
|
def self.register!(params = {})
|
3
5
|
unless @getaddress = params[:getaddress]
|
@@ -22,7 +24,7 @@ class ResolverReplace
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def self.load_plugin(name)
|
25
|
-
|
27
|
+
require "resolver_replace/plugins/#{name}"
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -1,14 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
unless defined?(Mysql2)
|
2
|
+
raise ResolverReplace::PluginLoadError, "mysql2 gem is not required"
|
3
|
+
end
|
4
|
+
module Mysql2
|
5
|
+
class Client
|
6
|
+
alias original_resolver_connect connect
|
7
|
+
def connect user, pass, host, port, database, socket, flags
|
8
|
+
begin
|
9
|
+
ip = ResolverReplace.getaddress(host).to_s
|
10
|
+
original_resolver_connect user, pass, ip, port, database, socket, flags
|
11
|
+
rescue ResolverReplace.error_class => e
|
12
|
+
raise Mysql2::Error, "#{e.class}: #{e.message}"
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
data/resolver_replace.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "resolver_replace"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.2"
|
8
8
|
spec.authors = ["Naotoshi Seo"]
|
9
9
|
spec.email = ["sonots@gmail.com"]
|
10
10
|
spec.summary = %q{Replace the DNS resolver}
|
@@ -26,17 +26,23 @@ describe ResolverReplace do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
29
|
+
context 'mysql2' do
|
30
|
+
it 'load error' do
|
31
|
+
expect { ResolverReplace.load_plugin("mysql2") }.to raise_error(ResolverReplace::PluginLoadError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'load' do
|
35
|
+
require 'mysql2'
|
36
|
+
ResolverReplace.load_plugin("mysql2")
|
37
|
+
begin
|
38
|
+
Mysql2::Client.new(
|
39
|
+
host: 'foo',
|
40
|
+
username: 'root',
|
41
|
+
database: 'foo',
|
42
|
+
)
|
43
|
+
rescue => e
|
44
|
+
expect(e.message).not_to match(/Unknown MySQL server/)
|
45
|
+
end
|
40
46
|
end
|
41
47
|
end
|
42
48
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resolver_replace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,6 +87,7 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- ".gitignore"
|
90
91
|
- CHANGELOG.md
|
91
92
|
- Gemfile
|
92
93
|
- Gemfile.lock
|
@@ -95,6 +96,7 @@ files:
|
|
95
96
|
- Rakefile
|
96
97
|
- example/example.rb
|
97
98
|
- lib/resolver_replace.rb
|
99
|
+
- lib/resolver_replace/error.rb
|
98
100
|
- lib/resolver_replace/plugins/mysql2.rb
|
99
101
|
- resolver_replace.gemspec
|
100
102
|
- spec/resolver_replace_spec.rb
|