arproxy 0.1.1 → 0.1.2
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.
- data/lib/arproxy/config.rb +9 -2
- data/lib/arproxy.rb +20 -4
- metadata +20 -6
data/lib/arproxy/config.rb
CHANGED
@@ -14,8 +14,15 @@ module Arproxy
|
|
14
14
|
|
15
15
|
def adapter_class
|
16
16
|
raise Arproxy::Error, "config.adapter must be set" unless @adapter
|
17
|
-
|
18
|
-
|
17
|
+
case @adapter
|
18
|
+
when String
|
19
|
+
camelized_adapter_name = @adapter.split("_").map(&:capitalize).join
|
20
|
+
eval "::ActiveRecord::ConnectionAdapters::#{camelized_adapter_name}Adapter"
|
21
|
+
when Class
|
22
|
+
@adapter
|
23
|
+
else
|
24
|
+
raise Arproxy::Error, "unexpected config.adapter: #{@adapter}"
|
25
|
+
end
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
data/lib/arproxy.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "logger"
|
2
|
+
require "active_record"
|
2
3
|
|
3
4
|
module Arproxy
|
4
5
|
autoload :Config, "arproxy/config"
|
@@ -14,6 +15,18 @@ module Arproxy
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def enable!
|
18
|
+
if @enabled
|
19
|
+
Arproxy.logger.warn "Arproxy has been already enabled"
|
20
|
+
return
|
21
|
+
end
|
22
|
+
|
23
|
+
unless @config
|
24
|
+
raise Arproxy::Error, "Arproxy should be configured"
|
25
|
+
end
|
26
|
+
|
27
|
+
# for lazy loading
|
28
|
+
ActiveRecord::Base
|
29
|
+
|
17
30
|
@proxy_chain = ProxyChain.new @config
|
18
31
|
|
19
32
|
@config.adapter_class.class_eval do
|
@@ -25,15 +38,18 @@ module Arproxy
|
|
25
38
|
alias_method :execute, :execute_with_arproxy
|
26
39
|
::Arproxy.logger.debug("Arproxy: Enabled")
|
27
40
|
end
|
41
|
+
@enabled = true
|
28
42
|
end
|
29
43
|
|
30
44
|
def disable!
|
31
|
-
@config
|
32
|
-
|
33
|
-
|
45
|
+
if @config
|
46
|
+
@config.adapter_class.class_eval do
|
47
|
+
alias_method :execute, :execute_without_arproxy
|
48
|
+
::Arproxy.logger.debug("Arproxy: Disabled")
|
49
|
+
end
|
34
50
|
end
|
35
51
|
@proxy_chain = nil
|
36
|
-
@
|
52
|
+
@enabled = false
|
37
53
|
end
|
38
54
|
|
39
55
|
def logger
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arproxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Issei Naruta
|
@@ -15,9 +15,23 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
19
|
-
dependencies:
|
20
|
-
|
18
|
+
date: 2012-07-29 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activerecord
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 0
|
32
|
+
version: "3.0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
21
35
|
description: Arproxy is a proxy between ActiveRecord and database adapter
|
22
36
|
email: naruta@cookpad.com
|
23
37
|
executables: []
|