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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjE1ZjBmM2VmOTY5MTAwNjNlY2VhYTg4YTQ1MmIzOWQyZTJiZDdjNA==
4
+ ZDBmZWJiNmU3ZTQ2N2U2YmI5NjY2MWViMzNjMzZiYzg4NDU2MjE5ZA==
5
5
  data.tar.gz: !binary |-
6
- MmQ2NjNkOTE5ZWI3MzMzMjAyODkzYWIzODNiYmQwM2JmNzFiN2RhMg==
6
+ ODA1NTM3NTdlNDgzMGVhZmI5YjNkODMxYzhiMjhlNWNhZDBhNmUzNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Zjk5MTIzMDRhOTBiOTMyOTQ3YmYwYTE5Yjk4OTk2NGVjY2M5ODkxNDViZjRl
10
- ZjdmMjM1NzBjMzFjZWYwOTYwNGIyYTdkMTJiZGVjYjcwMjFlZjlhYzk3MmE1
11
- ODM3M2E1NWRkMGQ2NDgyMmVmZGQ4NGQ1OGZmMzkzZmM4NjRhZDg=
9
+ MmNhZmYxMzAyMjMxYzI4MmU3ZmMyNjczNmJhODkwMzYwYzBlNDA2OGZjNzE4
10
+ OGYxOTQ5NDE5YjEyODMzZmU5MmViODhkMjg0ZDRjZmNkZmZkZGVmNTA1NmU0
11
+ ZTM2MTJhY2U2MDdkZjY2NTBlZDNjMmEyNWI1ODIyNjYzODgzNWM=
12
12
  data.tar.gz: !binary |-
13
- MzNjOTNkOTRiZTgyOGRjZjRhNjUxN2Q4OTlkM2M2MWYzMjBkOGUwZjI4YTJl
14
- MmJlNGNlMTU1NTY3NGViNmJmNzUzMGE0NDdmMDMwYWUyYzFiN2Y1NWRhM2Ew
15
- M2Q3MzE1ZWIwZTNkNDEzYjZlYjUxOTE5YjY1ZTUwYWZkNWRiZTA=
13
+ YTE3MzZmZTQ3YzIyZTc5NWM1ZjU1MmUxMTQ0YjYxZDY4ZjgxZmY4Y2FlOWE3
14
+ N2VjNmJjOWI1MjQ4NWFkNjYzYzY4MTg0YmI1NDlkZWNhMzYwYzUwYjU1NWE5
15
+ YmEwODE0ZmFlMWM3ODc2ZjBjZTUxYmZkOWZjNzJiZTQwMGYwODg=
@@ -3,27 +3,45 @@ require 'active_record'
3
3
  require 'rails'
4
4
 
5
5
  module Contineo
6
- CONFIG = begin
7
- YAML.load_file(CONFIG_PATH)
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
- CONFIG.each do |db_env, connection_hash|
13
- env = db_env.split('_').last
10
+ def self.env(db_env)
11
+ db_env.split('_').last
12
+ end
14
13
 
15
- if db_env.split('_').size > 1 && ::Rails.env == env
16
- db = db_env.split('_'+env).first
17
-
18
- klass = Object.const_set(db.camelcase, Class.new(ActiveRecord::Base) {
19
- self.abstract_class = true
20
- def self.inherited(base)
21
- contineo
22
- end
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
- klass.define_singleton_method(:contineo) { establish_connection db_env }
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
@@ -1,7 +1,7 @@
1
1
  module Contineo
2
2
  # Returns the version of the currently loaded Contineo as a Gem::Version
3
3
  def self.version
4
- Gem::Version.new "0.1.0"
4
+ Gem::Version.new "0.1.1"
5
5
  end
6
6
 
7
7
  module VERSION #:nodoc:
@@ -1,11 +1,42 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Contineo multiple databases' do
4
- it "should return count for first database as zero" do
5
- Doctor.count.should be_zero
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
- it "should return count for second database as zero" do
9
- Teacher.count.should be_zero
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
@@ -1,9 +1,6 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.setup
3
3
 
4
- require 'coveralls'
5
- Coveralls.wear!
6
-
7
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
8
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contineo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikhil Nanjappa