contineo 0.1.0 → 0.1.1
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 +8 -8
- data/lib/contineo.rb +34 -16
- data/lib/contineo/version.rb +1 -1
- data/spec/contineo_spec.rb +35 -4
- data/spec/spec_helper.rb +0 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDBmZWJiNmU3ZTQ2N2U2YmI5NjY2MWViMzNjMzZiYzg4NDU2MjE5ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODA1NTM3NTdlNDgzMGVhZmI5YjNkODMxYzhiMjhlNWNhZDBhNmUzNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmNhZmYxMzAyMjMxYzI4MmU3ZmMyNjczNmJhODkwMzYwYzBlNDA2OGZjNzE4
|
10
|
+
OGYxOTQ5NDE5YjEyODMzZmU5MmViODhkMjg0ZDRjZmNkZmZkZGVmNTA1NmU0
|
11
|
+
ZTM2MTJhY2U2MDdkZjY2NTBlZDNjMmEyNWI1ODIyNjYzODgzNWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTE3MzZmZTQ3YzIyZTc5NWM1ZjU1MmUxMTQ0YjYxZDY4ZjgxZmY4Y2FlOWE3
|
14
|
+
N2VjNmJjOWI1MjQ4NWFkNjYzYzY4MTg0YmI1NDlkZWNhMzYwYzUwYjU1NWE5
|
15
|
+
YmEwODE0ZmFlMWM3ODc2ZjBjZTUxYmZkOWZjNzJiZTQwMGYwODg=
|
data/lib/contineo.rb
CHANGED
@@ -3,27 +3,45 @@ require 'active_record'
|
|
3
3
|
require 'rails'
|
4
4
|
|
5
5
|
module Contineo
|
6
|
-
|
7
|
-
|
8
|
-
rescue NameError => e
|
9
|
-
YAML.load_file("config/database.yml")
|
6
|
+
def self.db(db_env)
|
7
|
+
db_env.split('_'+ env(db_env)).first.camelcase
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
def self.env(db_env)
|
11
|
+
db_env.split('_').last
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
def self.other_than_application_db?(db_env)
|
15
|
+
db_env.split('_').size > 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.define_db_connection_class(db_env)
|
19
|
+
klass = Object.const_set(db(db_env), Class.new(ActiveRecord::Base) {
|
20
|
+
self.abstract_class = true
|
21
|
+
def self.inherited(base)
|
22
|
+
contineo
|
23
|
+
end
|
24
|
+
})
|
24
25
|
|
25
|
-
|
26
|
+
klass.define_singleton_method(:contineo) { establish_connection db_env }
|
27
|
+
klass
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.configurations
|
31
|
+
begin
|
32
|
+
YAML.load_file(CONFIG_PATH)
|
33
|
+
rescue NameError => e
|
34
|
+
YAML.load_file("config/database.yml")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.create_connections
|
39
|
+
configurations.each do |db_env, connection_hash|
|
40
|
+
if other_than_application_db?(db_env) && ::Rails.env == env(db_env)
|
41
|
+
define_db_connection_class(db_env)
|
42
|
+
end
|
26
43
|
end
|
27
44
|
end
|
28
45
|
|
46
|
+
create_connections
|
29
47
|
end
|
data/lib/contineo/version.rb
CHANGED
data/spec/contineo_spec.rb
CHANGED
@@ -1,11 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Contineo multiple databases' do
|
4
|
-
|
5
|
-
|
4
|
+
context "test connection and run basic AREL query" do
|
5
|
+
it "should return count for first database as zero" do
|
6
|
+
Doctor.count.should be_zero
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return count for second database as zero" do
|
10
|
+
Teacher.count.should be_zero
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context '.env' do
|
15
|
+
it 'should return environment name from configuration name' do
|
16
|
+
Contineo.env('other_db_qa').should == 'qa'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '.db' do
|
21
|
+
it 'should return db class from configuration name' do
|
22
|
+
Contineo.db('other_db_qa').should == 'OtherDb'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '.other_than_application_db?' do
|
27
|
+
it 'should return true when db in question is other than application db' do
|
28
|
+
Contineo.other_than_application_db?('other_db_qa').should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should return false when db in question is application db' do
|
32
|
+
Contineo.other_than_application_db?('qa').should be_false
|
33
|
+
end
|
6
34
|
end
|
7
35
|
|
8
|
-
|
9
|
-
|
36
|
+
context '.define_db_connection_class' do
|
37
|
+
it 'should define connection class for First DB with contineo method' do
|
38
|
+
Contineo.define_db_connection_class('other_db_qa').should == OtherDb
|
39
|
+
OtherDb.respond_to?('contineo').should be_true
|
40
|
+
end
|
10
41
|
end
|
11
42
|
end
|
data/spec/spec_helper.rb
CHANGED