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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13a898dc3155fb550affbfe858cb070d033e2d74
4
- data.tar.gz: dcfc046f9e40bade813df3f46715667965e2bf46
3
+ metadata.gz: aaf2d6d3e1a9b1b8343440183c70d570a1d0a2c4
4
+ data.tar.gz: 5d1c057c384ddc95a09b62d08d323d5dec73a5e3
5
5
  SHA512:
6
- metadata.gz: e498affc9788ec2e3bac1dd092d9bac53eceba8a83e925b567537b8fbc7025366777bf55324e186685824f55ae22675328824f9d6530255f1ea5caa0d8be57ab
7
- data.tar.gz: f5c747339d275a779a66defce9c1575eef9845afd71353ac2fa64372296237c2bd67d074fab1879ee42fb5c0fc764d2d4704600c21fb9fd3c14a6a43da14df85
6
+ metadata.gz: c9dc86bdb74db1b6fbfff10336f4bb25a36a464153a0974a83e82678b2bddad989da5b9160ea3d64635e4f92938f12a81414aaefba9e23fcbb3b7f8e4b59d940
7
+ data.tar.gz: 7d4233e457e5448abb47aeec0f242e92c10aff38c0ad36fdf5bd3347641bea99d126a01543a80a43925c76e6b398cc86b8b74df1626ddeb53ccb52d647633488
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ spec/log/
16
+ spec/cache*
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
@@ -1,3 +1,9 @@
1
+ ## 0.0.2 (2014/06/27)
2
+
3
+ Enhancements:
4
+
5
+ * raise PluginLoadError if a required gem for the plugin is not loaded
6
+
1
7
  ## 0.0.1
2
8
 
3
9
  First version
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- resolver_replace (0.0.1)
4
+ resolver_replace (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 'resolve' # Resolve::DNS
24
- require 'resolver-replace' # ResolverReplace
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.configure(
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.configure(
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,
@@ -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
- load "resolver_replace/plugins/#{name}.rb"
27
+ require "resolver_replace/plugins/#{name}"
26
28
  end
27
29
  end
28
30
 
@@ -0,0 +1,3 @@
1
+ class ResolverReplace
2
+ class PluginLoadError < StandardError; end
3
+ end
@@ -1,14 +1,15 @@
1
- if defined?(Mysql2)
2
- module Mysql2
3
- class Client
4
- alias original_resolver_connect connect
5
- def connect user, pass, host, port, database, socket, flags
6
- begin
7
- ip = ResolverReplace.getaddress(host).to_s
8
- original_resolver_connect user, pass, ip, port, database, socket, flags
9
- rescue ResolverReplace.error_class => e
10
- raise Mysql2::Error, "#{e.class}: #{e.message}"
11
- end
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
@@ -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.1"
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
- it 'mysql2' do
30
- require 'mysql2'
31
- ResolverReplace.load_plugin("mysql2")
32
- begin
33
- Mysql2::Client.new(
34
- host: 'foo',
35
- username: 'root',
36
- database: 'foo',
37
- )
38
- rescue => e
39
- expect(e.message).not_to match(/Unknown MySQL server/)
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
@@ -2,7 +2,7 @@
2
2
  require 'rubygems'
3
3
  require 'bundler'
4
4
  Bundler.setup(:default, :test)
5
- Bundler.require(:default, :test)
5
+ #Bundler.require(:default, :test)
6
6
  require 'pry'
7
7
  ROOT = File.dirname(File.dirname(__FILE__))
8
8
 
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.1
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-25 00:00:00.000000000 Z
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