dbhijacker 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/hijacker.gemspec +1 -1
  2. data/lib/hijacker.rb +36 -28
  3. metadata +4 -4
data/hijacker.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{dbhijacker}
5
5
  s.homepage = "https://github.com/crystalcommerce/hijacker"
6
- s.version = "0.4.6"
6
+ s.version = "0.4.7"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.authors = ["Michael Xavier", "Donald Plummer", "Woody Peterson"]
data/lib/hijacker.rb CHANGED
@@ -31,42 +31,50 @@ module Hijacker
31
31
  # Note that you can manually call this from script/console (or wherever)
32
32
  # to connect to the database you want, ex Hijacker.connect("database")
33
33
  def self.connect(target_name, sister_name = nil, options = {})
34
- raise InvalidDatabase, 'master cannot be nil' if target_name.nil?
34
+ original_database = Hijacker::Database.current
35
35
 
36
- target_name = target_name.downcase
37
- sister_name = sister_name.downcase unless sister_name.nil?
36
+ begin
37
+ raise InvalidDatabase, 'master cannot be nil' if target_name.nil?
38
38
 
39
- if already_connected?(target_name, sister_name)
40
- return "Already connected to #{target_name}"
41
- end
39
+ target_name = target_name.downcase
40
+ sister_name = sister_name.downcase unless sister_name.nil?
42
41
 
43
- verify = options.fetch(:verify, Hijacker.do_hijacking?)
42
+ if already_connected?(target_name, sister_name)
43
+ return "Already connected to #{target_name}"
44
+ end
44
45
 
45
- database = determine_database(target_name, sister_name, verify)
46
+ verify = options.fetch(:verify, Hijacker.do_hijacking?)
46
47
 
47
- establish_connection_to_database(database)
48
+ database = determine_database(target_name, sister_name, verify)
48
49
 
49
- check_connection
50
+ establish_connection_to_database(database)
50
51
 
51
- if database.sister?
52
- self.master = database.master.name
53
- self.sister = database.name
54
- else
55
- self.master = database.name
56
- self.sister = nil
57
- end
52
+ check_connection
53
+
54
+ if database.sister?
55
+ self.master = database.master.name
56
+ self.sister = database.name
57
+ else
58
+ self.master = database.name
59
+ self.sister = nil
60
+ end
58
61
 
59
- # don't cache sister site
60
- cache_database_route(target_name, database) unless sister_name
61
-
62
- connect_sister_site_models(target_name)
63
-
64
- reenable_query_caching
65
-
66
- self.config[:after_hijack].call if self.config[:after_hijack]
67
- rescue
68
- self.establish_root_connection
69
- raise
62
+ # don't cache sister site
63
+ cache_database_route(target_name, database) unless sister_name
64
+
65
+ connect_sister_site_models(target_name)
66
+
67
+ reenable_query_caching
68
+
69
+ self.config[:after_hijack].call if self.config[:after_hijack]
70
+ rescue
71
+ if original_database.present?
72
+ establish_connection_to_database(original_database)
73
+ else
74
+ self.establish_root_connection
75
+ end
76
+ raise
77
+ end
70
78
  end
71
79
 
72
80
  # very small chance this will raise, but if it does, we will still handle it the
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbhijacker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 6
10
- version: 0.4.6
9
+ - 7
10
+ version: 0.4.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Xavier
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  requirements: []
196
196
 
197
197
  rubyforge_project:
198
- rubygems_version: 1.8.17
198
+ rubygems_version: 1.8.24
199
199
  signing_key:
200
200
  specification_version: 3
201
201
  summary: One application, multiple client databases