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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59843051a36bb5d7d2d9d22a261a9f2d5e71dbdd
4
- data.tar.gz: 2f7c00567922a84937e26c9fa4b2682fabdcd7cd
3
+ metadata.gz: 27bd84658cafc198ccd70f575641e2d15e06e6a5
4
+ data.tar.gz: e78fd168551b4286342dcc283091b1a9b030745e
5
5
  SHA512:
6
- metadata.gz: 197c4375c817d11ad36058a9e28ca39ec1720e137cc0ac7ef574431affc94d4a9279047481073aa59fa8fdd83978f7980ebb1f659397fd6180bc0eebad339c77
7
- data.tar.gz: 0b30b39693e8a51bbf596677c523e4e1bf2dc4dbe08e5ba29c637e2fae994b30453a8f740c8e1dc23817aa8338eb835a90ee7318f06c274f747971ab4dcd6b02
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(pool_name: nil, &block)
4
+ def with_connection(key: nil)
5
+ key ||= db_name
6
+ db = directory(key)
5
7
  retryable(sleep: 0.5) do
6
- connection_pool(pool_name: pool_name).with &block
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 connection_pool(pool_name: nil)
11
- self.class.connection_pool(pool_name: pool_name)
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 pool(pool_name)
19
- @pool_name = pool_name
27
+ def set_db(db_name)
28
+ @db_name = db_name
20
29
  end
21
30
 
22
- def pool_name
23
- @pool_name
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
@@ -2,7 +2,7 @@ module Bellbro
2
2
  module Settings
3
3
 
4
4
  class SettingsData < Struct.new(
5
- :logger, :env, :connection_pools
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.connection_pools
27
+ def self.connection_pool
28
28
  return unless configured?
29
- configuration.connection_pools
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
@@ -1,3 +1,3 @@
1
1
  module Bellbro
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
data/lib/bellbro.rb CHANGED
@@ -19,6 +19,7 @@ require 'airbrake'
19
19
  bellbro/bell.rb
20
20
  bellbro/service.rb
21
21
  bellbro/worker.rb
22
+ bellbro/initialize.rb
22
23
  ).each do |path|
23
24
  require File.join(File.dirname(__FILE__),path)
24
25
  end
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.2
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 00:00:00.000000000 Z
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