arproxy 0.1.2 → 0.1.3
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 +7 -0
- data/lib/arproxy.rb +33 -25
- data/lib/arproxy/config.rb +2 -2
- data/lib/arproxy/proxy_chain.rb +29 -5
- data/lib/arproxy/version.rb +3 -0
- metadata +34 -55
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 191862b3b6b33176695a8d12e0111c25f966dfd7
|
4
|
+
data.tar.gz: 8862e8f9fd12c7d3d25d40572f4377a798a0a8e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40fbee48d349461d7306ec13905eb262d1f52d48cb8cdad2cd15dd29e3be0cf6525c3e3848d176109dddd1b138a80c7c0edb40f2a69a1d9b55d2369a392af40b
|
7
|
+
data.tar.gz: 590181c81ca59b274aa493dafa309e78e8cac06838d329cce93029820d338aa1a2f0fc8756985119660804af34852e13a6ac2563fd0505dbe747e907c8f69f35
|
data/lib/arproxy.rb
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
require "logger"
|
2
2
|
require "active_record"
|
3
|
+
require "arproxy/base"
|
4
|
+
require "arproxy/config"
|
5
|
+
require "arproxy/proxy_chain"
|
6
|
+
require "arproxy/error"
|
3
7
|
|
4
8
|
module Arproxy
|
5
|
-
autoload :Config, "arproxy/config"
|
6
|
-
autoload :ProxyChain, "arproxy/proxy_chain"
|
7
|
-
autoload :Error, "arproxy/error"
|
8
|
-
autoload :Base, "arproxy/base"
|
9
9
|
|
10
10
|
module_function
|
11
|
+
def clear_configuration
|
12
|
+
@config = Config.new
|
13
|
+
end
|
14
|
+
|
11
15
|
def configure
|
12
|
-
|
13
|
-
yield config
|
14
|
-
@config = config
|
16
|
+
clear_configuration unless @config
|
17
|
+
yield @config
|
15
18
|
end
|
16
19
|
|
17
20
|
def enable!
|
18
|
-
if
|
21
|
+
if enable?
|
19
22
|
Arproxy.logger.warn "Arproxy has been already enabled"
|
20
23
|
return
|
21
24
|
end
|
@@ -25,33 +28,39 @@ module Arproxy
|
|
25
28
|
end
|
26
29
|
|
27
30
|
# for lazy loading
|
28
|
-
ActiveRecord::Base
|
31
|
+
::ActiveRecord::Base
|
29
32
|
|
30
33
|
@proxy_chain = ProxyChain.new @config
|
34
|
+
@proxy_chain.enable!
|
31
35
|
|
32
|
-
@config.adapter_class.class_eval do
|
33
|
-
def execute_with_arproxy(sql, name=nil)
|
34
|
-
::Arproxy.proxy_chain.connection = self
|
35
|
-
::Arproxy.proxy_chain.head.execute sql, name
|
36
|
-
end
|
37
|
-
alias_method :execute_without_arproxy, :execute
|
38
|
-
alias_method :execute, :execute_with_arproxy
|
39
|
-
::Arproxy.logger.debug("Arproxy: Enabled")
|
40
|
-
end
|
41
36
|
@enabled = true
|
42
37
|
end
|
43
38
|
|
44
39
|
def disable!
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
40
|
+
unless enable?
|
41
|
+
Arproxy.logger.warn "Arproxy is not enabled yet"
|
42
|
+
return
|
43
|
+
end
|
44
|
+
|
45
|
+
if @proxy_chain
|
46
|
+
@proxy_chain.disable!
|
47
|
+
@proxy_chain = nil
|
50
48
|
end
|
51
|
-
@proxy_chain = nil
|
52
49
|
@enabled = false
|
53
50
|
end
|
54
51
|
|
52
|
+
def enable?
|
53
|
+
!!@enabled
|
54
|
+
end
|
55
|
+
|
56
|
+
def reenable!
|
57
|
+
if enable?
|
58
|
+
@proxy_chain.reenable!
|
59
|
+
else
|
60
|
+
enable!
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
55
64
|
def logger
|
56
65
|
@logger ||= begin
|
57
66
|
@config && @config.logger ||
|
@@ -64,4 +73,3 @@ module Arproxy
|
|
64
73
|
@proxy_chain
|
65
74
|
end
|
66
75
|
end
|
67
|
-
|
data/lib/arproxy/config.rb
CHANGED
@@ -15,8 +15,8 @@ module Arproxy
|
|
15
15
|
def adapter_class
|
16
16
|
raise Arproxy::Error, "config.adapter must be set" unless @adapter
|
17
17
|
case @adapter
|
18
|
-
when String
|
19
|
-
camelized_adapter_name = @adapter.split("_").map(&:capitalize).join
|
18
|
+
when String, Symbol
|
19
|
+
camelized_adapter_name = @adapter.to_s.split("_").map(&:capitalize).join
|
20
20
|
eval "::ActiveRecord::ConnectionAdapters::#{camelized_adapter_name}Adapter"
|
21
21
|
when Class
|
22
22
|
@adapter
|
data/lib/arproxy/proxy_chain.rb
CHANGED
@@ -7,20 +7,44 @@ module Arproxy
|
|
7
7
|
|
8
8
|
def initialize(config)
|
9
9
|
@config = config
|
10
|
-
|
10
|
+
setup
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def setup
|
14
14
|
@tail = ChainTail.new self
|
15
|
-
@head = config.proxies.reverse.inject(@tail) do |next_proxy, proxy_config|
|
15
|
+
@head = @config.proxies.reverse.inject(@tail) do |next_proxy, proxy_config|
|
16
16
|
cls, options = proxy_config
|
17
|
-
proxy = cls.new
|
17
|
+
proxy = cls.new(*options)
|
18
18
|
proxy.proxy_chain = self
|
19
19
|
proxy.next_proxy = next_proxy
|
20
20
|
proxy
|
21
21
|
end
|
22
22
|
end
|
23
|
-
private :
|
23
|
+
private :setup
|
24
24
|
|
25
|
+
def reenable!
|
26
|
+
disable!
|
27
|
+
setup
|
28
|
+
enable!
|
29
|
+
end
|
30
|
+
|
31
|
+
def enable!
|
32
|
+
@config.adapter_class.class_eval do
|
33
|
+
def execute_with_arproxy(sql, name=nil)
|
34
|
+
::Arproxy.proxy_chain.connection = self
|
35
|
+
::Arproxy.proxy_chain.head.execute sql, name
|
36
|
+
end
|
37
|
+
alias_method :execute_without_arproxy, :execute
|
38
|
+
alias_method :execute, :execute_with_arproxy
|
39
|
+
::Arproxy.logger.debug("Arproxy: Enabled")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def disable!
|
44
|
+
@config.adapter_class.class_eval do
|
45
|
+
alias_method :execute, :execute_without_arproxy
|
46
|
+
::Arproxy.logger.debug("Arproxy: Disabled")
|
47
|
+
end
|
48
|
+
end
|
25
49
|
end
|
26
50
|
end
|
metadata
CHANGED
@@ -1,84 +1,63 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: arproxy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 2
|
10
|
-
version: 0.1.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Issei Naruta
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: activerecord
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 7
|
29
|
-
segments:
|
30
|
-
- 3
|
31
|
-
- 0
|
32
|
-
version: "3.0"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
33
20
|
type: :runtime
|
34
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
35
27
|
description: Arproxy is a proxy between ActiveRecord and database adapter
|
36
28
|
email: naruta@cookpad.com
|
37
29
|
executables: []
|
38
|
-
|
39
30
|
extensions: []
|
40
|
-
|
41
31
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
files:
|
32
|
+
files:
|
44
33
|
- lib/arproxy/base.rb
|
45
34
|
- lib/arproxy/chain_tail.rb
|
46
35
|
- lib/arproxy/config.rb
|
47
36
|
- lib/arproxy/error.rb
|
48
37
|
- lib/arproxy/proxy_chain.rb
|
38
|
+
- lib/arproxy/version.rb
|
49
39
|
- lib/arproxy.rb
|
50
40
|
homepage: https://github.com/cookpad/arproxy
|
51
41
|
licenses: []
|
52
|
-
|
42
|
+
metadata: {}
|
53
43
|
post_install_message:
|
54
44
|
rdoc_options: []
|
55
|
-
|
56
|
-
require_paths:
|
45
|
+
require_paths:
|
57
46
|
- lib
|
58
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
none: false
|
69
|
-
requirements:
|
70
|
-
- - ">="
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
hash: 3
|
73
|
-
segments:
|
74
|
-
- 0
|
75
|
-
version: "0"
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
76
57
|
requirements: []
|
77
|
-
|
78
58
|
rubyforge_project:
|
79
|
-
rubygems_version:
|
59
|
+
rubygems_version: 2.0.2
|
80
60
|
signing_key:
|
81
|
-
specification_version:
|
61
|
+
specification_version: 4
|
82
62
|
summary: Proxy between ActiveRecord and DB adapter
|
83
63
|
test_files: []
|
84
|
-
|