with_connection 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -0,0 +1,25 @@
1
+ module ActiveSupport
2
+ module Cache
3
+ module Features
4
+ module AdapterMethods
5
+ # method required by ActiveRecord::ConnectionAdapters::ConnectionPool
6
+ def run_callbacks(method)
7
+ end
8
+
9
+ def verify!
10
+ end
11
+
12
+ def _run_checkin_callbacks
13
+ yield if block_given?
14
+ end
15
+
16
+ def requires_reloading?
17
+ true
18
+ end
19
+
20
+ def connected?
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,106 @@
1
+ module ActiveSupport
2
+ module Cache
3
+ class MemcacheConnectionPool
4
+ attr_reader :options
5
+
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+
10
+ def fetch(name, options=nil)
11
+ with_connection do
12
+ connection.fetch name, options
13
+ end
14
+ end
15
+
16
+ def read(name, options=nil)
17
+ with_connection do
18
+ connection.read name, options
19
+ end
20
+ end
21
+
22
+ def write(name, value, options=nil)
23
+ with_connection do
24
+ connection.write name, value, options
25
+ end
26
+ end
27
+
28
+ def exist?(name, options=nil)
29
+ with_connection do
30
+ connection.exist? name, options
31
+ end
32
+ end
33
+
34
+ def delete(name, options=nil)
35
+ with_connection do
36
+ connection.delete name, options
37
+ end
38
+ end
39
+
40
+ def read_multi(*names)
41
+ with_connection do
42
+ connection.read_multi *names
43
+ end
44
+ end
45
+
46
+ def increment(name, amount = 1, options=nil)
47
+ with_connection do
48
+ connection.increment name, amount, options
49
+ end
50
+ end
51
+
52
+ def decrement(name, amount = 1, options=nil)
53
+ with_connection do
54
+ connection.decrement name, amount, options
55
+ end
56
+ end
57
+
58
+ def reset(options={})
59
+ with_connection do
60
+ connection.reset options
61
+ end
62
+ end
63
+ alias clear reset
64
+
65
+ private
66
+
67
+ if defined?(EM)
68
+ def sync_connection_pool
69
+ @sync_connection_pool ||=
70
+ begin
71
+ spec = ActiveRecord::Base::ConnectionSpecification.new @options.dup, @options[:adapter_method]
72
+ WithConnection::ConnectionPool.new @options[:name], spec
73
+ end
74
+ end
75
+
76
+ def async_connection_pool
77
+ @async_connection_pool ||=
78
+ begin
79
+ spec = ActiveRecord::Base::ConnectionSpecification.new @options.merge(:async => true), (@options[:async_adapter_method] || @options[:adapter_method])
80
+ WithConnection::ConnectionPool.new @options[:name], spec
81
+ end
82
+ end
83
+
84
+ def connection_pool
85
+ EM.reactor_running? ? async_connection_pool : sync_connection_pool
86
+ end
87
+ else
88
+ def connection_pool
89
+ @connection_pool ||=
90
+ begin
91
+ spec = ActiveRecord::Base::ConnectionSpecification.new @options.dup, @options[:adapter_method]
92
+ WithConnection::ConnectionPool.new @options[:name], spec
93
+ end
94
+ end
95
+ end
96
+
97
+ def with_connection(&block)
98
+ connection_pool.with_connection(&block)
99
+ end
100
+
101
+ def connection
102
+ connection_pool.connection
103
+ end
104
+ end
105
+ end
106
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "with_connection"
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Doug Youch"]
@@ -26,6 +26,8 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "lib/active_record/fiber_patches.rb",
29
+ "lib/active_support/cache/features/adapter_methods.rb",
30
+ "lib/active_support/cache/memcache_connection_pool.rb",
29
31
  "lib/with_connection.rb",
30
32
  "lib/with_connection/connection_pool.rb",
31
33
  "with_connection.gemspec"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -92,6 +92,8 @@ files:
92
92
  - Rakefile
93
93
  - VERSION
94
94
  - lib/active_record/fiber_patches.rb
95
+ - lib/active_support/cache/features/adapter_methods.rb
96
+ - lib/active_support/cache/memcache_connection_pool.rb
95
97
  - lib/with_connection.rb
96
98
  - lib/with_connection/connection_pool.rb
97
99
  - with_connection.gemspec
@@ -110,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
112
  version: '0'
111
113
  segments:
112
114
  - 0
113
- hash: 271538820517515864
115
+ hash: 3405355780874312371
114
116
  required_rubygems_version: !ruby/object:Gem::Requirement
115
117
  none: false
116
118
  requirements: