bellbro 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bellbro/initialize.rb +30 -0
- data/lib/bellbro/pool.rb +17 -12
- data/lib/bellbro/settings.rb +8 -3
- data/lib/bellbro/version.rb +1 -1
- data/lib/bellbro.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27bd84658cafc198ccd70f575641e2d15e06e6a5
|
4
|
+
data.tar.gz: e78fd168551b4286342dcc283091b1a9b030745e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33ab6289d05aa2c613f86d9350197145e7bb50b98712a265cfde38f43607b4f04a986b1e44a9d00fc6fafeb6cc3b2ccb5f42efc96c678e455a7cfe9b94be2965
|
7
|
+
data.tar.gz: b56eb341446b9b0f9744b5d67462044e089a2f95b3b6865ef8b342dcf47a1df5254a71a3f5d2a48534c412c9c21640eb4cc60f20e9279c5cc7a44e7baa2cc8f1
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Bellbro
|
2
|
+
def self.initialize!
|
3
|
+
return unless defined?(Rails)
|
4
|
+
filename = "#{Rails.root}/config/redis.yml"
|
5
|
+
return unless File.exists?(filename)
|
6
|
+
|
7
|
+
config = YAML.load_file(filename)[Rails.env]
|
8
|
+
url = Figaro.env.send(config['url'].downcase)
|
9
|
+
size = config['pool']
|
10
|
+
|
11
|
+
puts "## Initializing redis pool with size #{size} and url #{url}"
|
12
|
+
pool = ConnectionPool.new(size: size) do
|
13
|
+
Redis.new(url: url)
|
14
|
+
end
|
15
|
+
|
16
|
+
directory = ThreadSafe::Cache.new
|
17
|
+
config['databases'].each do |name, db|
|
18
|
+
puts "## Db name #{name} mapped to #{db}"
|
19
|
+
directory[name.to_sym] = db
|
20
|
+
end
|
21
|
+
|
22
|
+
Bellbro::Settings.configure do |config|
|
23
|
+
config.connection_pool = pool
|
24
|
+
config.db_directory = directory
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Bellbro.initialize!
|
30
|
+
|
data/lib/bellbro/pool.rb
CHANGED
@@ -1,30 +1,35 @@
|
|
1
1
|
module Bellbro
|
2
2
|
module Pool
|
3
3
|
|
4
|
-
def with_connection(
|
4
|
+
def with_connection(key: nil)
|
5
|
+
key ||= db_name
|
6
|
+
db = directory(key)
|
5
7
|
retryable(sleep: 0.5) do
|
6
|
-
connection_pool
|
8
|
+
Bellbro::Settings.connection_pool.with do |c|
|
9
|
+
c.select(db)
|
10
|
+
yield c
|
11
|
+
end
|
7
12
|
end
|
8
13
|
end
|
9
14
|
|
10
|
-
def
|
11
|
-
self.class.
|
15
|
+
def db_name
|
16
|
+
self.class.db_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def directory(name)
|
20
|
+
Bellbro::Settings.db_directory[name]
|
12
21
|
end
|
13
22
|
|
14
23
|
def self.included(klass)
|
15
24
|
klass.extend(self)
|
16
25
|
|
17
26
|
class << klass
|
18
|
-
def
|
19
|
-
|
27
|
+
def set_db(db_name)
|
28
|
+
@db_name = db_name
|
20
29
|
end
|
21
30
|
|
22
|
-
def
|
23
|
-
@
|
24
|
-
end
|
25
|
-
|
26
|
-
def connection_pool(pool_name: nil)
|
27
|
-
Bellbro::Settings.connection_pools[pool_name || @pool_name]
|
31
|
+
def db_name
|
32
|
+
@db_name
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
data/lib/bellbro/settings.rb
CHANGED
@@ -2,7 +2,7 @@ module Bellbro
|
|
2
2
|
module Settings
|
3
3
|
|
4
4
|
class SettingsData < Struct.new(
|
5
|
-
:logger, :env, :
|
5
|
+
:logger, :env, :connection_pool, :db_directory
|
6
6
|
)
|
7
7
|
end
|
8
8
|
|
@@ -24,9 +24,14 @@ module Bellbro
|
|
24
24
|
configuration.env == 'test'
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.
|
27
|
+
def self.connection_pool
|
28
28
|
return unless configured?
|
29
|
-
configuration.
|
29
|
+
configuration.connection_pool
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.db_directory
|
33
|
+
return unless configured?
|
34
|
+
configuration.db_directory
|
30
35
|
end
|
31
36
|
|
32
37
|
def self.logger
|
data/lib/bellbro/version.rb
CHANGED
data/lib/bellbro.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bellbro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Stokes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- lib/bellbro.rb
|
139
139
|
- lib/bellbro/bell.rb
|
140
140
|
- lib/bellbro/hooks.rb
|
141
|
+
- lib/bellbro/initialize.rb
|
141
142
|
- lib/bellbro/keyable.rb
|
142
143
|
- lib/bellbro/pool.rb
|
143
144
|
- lib/bellbro/retryable.rb
|