connection_manager 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gemspec
4
-
5
- gem 'ZenTest', '4.8.2'
3
+ gemspec
@@ -11,7 +11,7 @@ module ConnectionManager
11
11
 
12
12
  private
13
13
  # We use dup here because its just too tricky to make sure we override
14
- # all the methods nesseccary when using a child class of the model. This
14
+ # all the methods necessary when using a child class of the model. This
15
15
  # action is lazy and the created sub is named to a constant so we only
16
16
  # have to do it once.
17
17
  def fetch_duplicate_class(connection_class_name)
@@ -22,6 +22,11 @@ module ConnectionManager
22
22
  end
23
23
  end
24
24
 
25
+ # Modifies the dup class to use the connection class connection.
26
+ # We want to use the current class table name, but the connection
27
+ # class database as the prefix. We also want the superclass method to
28
+ # return the connection class as AR sometimes uses the the superclass
29
+ # connection
25
30
  def build_dup_class(connection_class_name)
26
31
  con_class = connection_class_name.constantize
27
32
  db_name = con_class.database_name
@@ -34,44 +39,20 @@ module ConnectionManager
34
39
  def model_name
35
40
  #{self.name}.model_name
36
41
  end
42
+ def connection_class
43
+ #{connection_class_name}
44
+ end
45
+ def connection
46
+ connection_class.connection
47
+ end
48
+ def superclass
49
+ connection_class
50
+ end
37
51
  end
38
52
  STR
39
53
 
40
- extend_dup_class(dup_klass,connection_class_name)
41
54
  self.const_set("#{connection_class_name}Dup", dup_klass)
42
55
  end
43
-
44
- # Extend the connection override module from the connetion to the supplied class
45
- def extend_dup_class(dup_class,connection_class_name)
46
- begin
47
- mod = "#{connection_class_name}::ConnectionOverrideMod".constantize
48
- dup_class.extend(mod)
49
- rescue NameError
50
- built = build_connection_override_module(connection_class_name).constantize
51
- dup_class.extend(built)
52
- end
53
- end
54
-
55
- # Added a module to the connection class. The module is extended on dup class
56
- # to override the connection and superclass
57
- def build_connection_override_module(connection_class_name)
58
- connection_class_name.constantize.class_eval <<-STR
59
- module ConnectionOverrideMod
60
- def connection_class
61
- #{connection_class_name}
62
- end
63
-
64
- def connection
65
- connection_class.connection
66
- end
67
-
68
- def superclass
69
- connection_class
70
- end
71
- end
72
- STR
73
- "#{connection_class_name}::ConnectionOverrideMod"
74
- end
75
56
  end
76
57
 
77
58
  # Instance method for casting to a duplication class
@@ -1,4 +1,3 @@
1
1
  module ConnectionManager
2
- VERSION = "0.3.8"
3
- end
4
-
2
+ VERSION = "0.3.9"
3
+ end
@@ -8,18 +8,6 @@ end
8
8
 
9
9
  describe ConnectionManager::Using do
10
10
 
11
- it "should add module to provided class" do
12
- Fruit.send(:build_connection_override_module,"CmFooSlaveConnection")
13
- lambda { "CmFooSlaveConnection::ConnectionOverrideMod".constantize}.should_not raise_error(NameError)
14
- end
15
-
16
- it "should extend to module to the supplied class" do
17
- Fruit.send(:build_connection_override_module,"CmFooSlaveConnection")
18
- d = Fruit.dup
19
- d.send(:extend_dup_class,d,"CmFooSlaveConnection")
20
- d.connection.config.should_not eql(Fruit.connection.config)
21
- end
22
-
23
11
  it "should add sub class to current class with the name of the connection" do
24
12
  Fruit.send(:fetch_duplicate_class,"CmFooSlaveConnection")
25
13
  lambda { "Fruit::CmFooSlaveConnectionDup".constantize}.should_not raise_error(NameError)
@@ -33,7 +21,7 @@ describe ConnectionManager::Using do
33
21
  Fruit.using("CmFooSlaveConnection").connection.config.should_not eql(Fruit.connection.config)
34
22
  end
35
23
 
36
- it "should create the same sql if called from model or from relation" #do
24
+ it "should create the exact same sql if called from model or from relation" #do
37
25
  # Fruit.where(:name => "malarky").using("CmFooSlaveConnection").to_sql.should eql(
38
26
  # Fruit.using("CmFooSlaveConnection").where(:name => "malarky").to_sql)
39
27
  # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connection_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
12
+ date: 2013-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  version: '0'
182
182
  requirements: []
183
183
  rubyforge_project: connection_manager
184
- rubygems_version: 1.8.24
184
+ rubygems_version: 1.8.25
185
185
  signing_key:
186
186
  specification_version: 3
187
187
  summary: Simplifies connecting to Muliple and Replication databases with rails and