shackles 1.0.2 → 1.0.3

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NWY1MDlmODBlNTc5NDVmZGNhZDY3ZWJlZjlhZTViMDExNjM5MDVkMA==
5
+ data.tar.gz: !binary |-
6
+ YWY1NTVhYmFjODI3YWMxNWRiODI1ZjM1MDRmNjQwOTZmNjc1OGNmNg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZjkwZDllYjZkNTE4Nzg2MzE2M2E4ODIzY2FkNTkzY2IyNGE3YTk4Nzk0NThl
10
+ Yjg5OTA0MjFkZDAyYWRhMjgzYjA3MmVjYmFmNGI0Njg2YWYxYzc0MmE5MjFk
11
+ NDhmYjAwMjM1ODJhYjQxMmQ4M2RiODA4NTgyZjNjOTFlOGViNzI=
12
+ data.tar.gz: !binary |-
13
+ YWU4ODE4OTMzZTA3ZjE0YzlmYWEwZDExMGFiZjBjN2I3MjVlMDBmY2FiZGI4
14
+ YWI5YzFkMzFkNmM4ZjAyYTlhNjE5ODIwNTYyYzdkMjE1NWY4MTllODg3MmRj
15
+ MzVlYjYzYzkwOWQyZTI2NTY5NzA3MGFkOWYxNGJmOTUzODJmNTQ=
@@ -3,6 +3,7 @@ module Shackles
3
3
  def self.included(klass)
4
4
  %w{clear_active_connections clear_reloadable_connections
5
5
  clear_all_connections verify_active_connections }.each do |method|
6
+ next unless klass.instance_methods.include?("#{method}!".to_sym)
6
7
  klass.class_eval(<<EOS)
7
8
  def #{method}_with_multiple_environments!
8
9
  ::Shackles.connection_handlers.values.each(&:#{method}_without_multiple_environments!)
@@ -1,3 +1,3 @@
1
1
  module Shackles
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
data/lib/shackles.rb CHANGED
@@ -13,8 +13,9 @@ module Shackles
13
13
  require 'shackles/connection_handler'
14
14
  require 'shackles/connection_specification'
15
15
 
16
- ActiveRecord::ConnectionAdapters::ConnectionHandler.send(:include, Shackles::ConnectionHandler)
17
- ActiveRecord::Base::ConnectionSpecification.send(:include, Shackles::ConnectionSpecification)
16
+ ActiveRecord::ConnectionAdapters::ConnectionHandler.send(:include, ConnectionHandler)
17
+ klass = Rails.version < '4' ? ActiveRecord::Base : ActiveRecord::ConnectionAdapters
18
+ klass::ConnectionSpecification.send(:include, ConnectionSpecification)
18
19
  end
19
20
 
20
21
  def global_config_sequence
@@ -78,8 +79,15 @@ module Shackles
78
79
  new_handler = @connection_handlers[environment]
79
80
  if !new_handler
80
81
  new_handler = @connection_handlers[environment] = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
81
- variable = Rails.version < '3.0' ? :@connection_pools : :@class_to_pool
82
- ActiveRecord::Base.connection_handler.instance_variable_get(variable).each do |model, pool|
82
+ pools = if Rails.version < '3.0'
83
+ ActiveRecord::Base.connection_handler.instance_variable_get(:@connection_pools)
84
+ elsif Rails.version < '4.0'
85
+ ActiveRecord::Base.connection_handler.instance_variable_get(:@class_to_pool)
86
+ else
87
+ ActiveRecord::Base.connection_handler.send(:owner_to_pool)
88
+ end
89
+ pools.each_pair do |model, pool|
90
+ model = model.constantize if Rails.version >= '4'
83
91
  new_handler.establish_connection(model, pool.spec)
84
92
  end
85
93
  end
@@ -10,6 +10,10 @@ RSpec.configure do |config|
10
10
  end
11
11
 
12
12
  describe Shackles do
13
+ ConnectionSpecification = Rails.version < '4' ?
14
+ ActiveRecord::Base::ConnectionSpecification :
15
+ ActiveRecord::ConnectionAdapters::ConnectionSpecification
16
+
13
17
  it "should allow changing environments" do
14
18
  conf = {
15
19
  :adapter => 'postgresql',
@@ -22,7 +26,7 @@ describe Shackles do
22
26
  :database => 'slave'
23
27
  }
24
28
  }
25
- spec = ActiveRecord::Base::ConnectionSpecification.new(conf, 'adapter')
29
+ spec = ConnectionSpecification.new(conf, 'adapter')
26
30
  spec.config[:username].should == 'canvas'
27
31
  spec.config[:database].should == 'master'
28
32
  Shackles.activate(:deploy) do
@@ -49,7 +53,7 @@ describe Shackles do
49
53
  :username => 'deploy'
50
54
  }
51
55
  }
52
- spec = ActiveRecord::Base::ConnectionSpecification.new(conf, 'adapter')
56
+ spec = ConnectionSpecification.new(conf, 'adapter')
53
57
  spec.config[:username].should == 'canvas'
54
58
  Shackles.activate(:deploy) do
55
59
  spec.config[:username].should == 'deploy'
@@ -67,7 +71,7 @@ describe Shackles do
67
71
  :username => 'deploy'
68
72
  }
69
73
  }
70
- spec = ActiveRecord::Base::ConnectionSpecification.new(conf.dup, 'adapter')
74
+ spec = ConnectionSpecification.new(conf.dup, 'adapter')
71
75
  spec.config[:username].should == 'canvas'
72
76
  spec.config[:schema_search_path] = 'bob'
73
77
  spec.config[:username].should == 'bob'
metadata CHANGED
@@ -1,36 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shackles
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
5
- prerelease:
4
+ version: 1.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Cody Cutrer
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-14 00:00:00.000000000 Z
11
+ date: 2014-03-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '2.3'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '4.1'
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '2.3'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '4.1'
30
33
  - !ruby/object:Gem::Dependency
31
- name: mocha
34
+ name: debugger
32
35
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
36
  requirements:
35
37
  - - ! '>='
36
38
  - !ruby/object:Gem::Version
@@ -38,31 +40,27 @@ dependencies:
38
40
  type: :development
39
41
  prerelease: false
40
42
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
43
  requirements:
43
44
  - - ! '>='
44
45
  - !ruby/object:Gem::Version
45
46
  version: '0'
46
47
  - !ruby/object:Gem::Dependency
47
- name: rspec-core
48
+ name: mocha
48
49
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
50
  requirements:
51
- - - ~>
51
+ - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: '2.13'
53
+ version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
57
  requirements:
59
- - - ~>
58
+ - - ! '>='
60
59
  - !ruby/object:Gem::Version
61
- version: '2.13'
60
+ version: '0'
62
61
  - !ruby/object:Gem::Dependency
63
62
  name: sqlite3
64
63
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
64
  requirements:
67
65
  - - ! '>='
68
66
  - !ruby/object:Gem::Version
@@ -70,7 +68,6 @@ dependencies:
70
68
  type: :development
71
69
  prerelease: false
72
70
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
71
  requirements:
75
72
  - - ! '>='
76
73
  - !ruby/object:Gem::Version
@@ -82,38 +79,37 @@ executables: []
82
79
  extensions: []
83
80
  extra_rdoc_files: []
84
81
  files:
82
+ - LICENSE
83
+ - README.md
84
+ - lib/shackles.rb
85
85
  - lib/shackles/connection_handler.rb
86
86
  - lib/shackles/connection_specification.rb
87
87
  - lib/shackles/railtie.rb
88
88
  - lib/shackles/version.rb
89
- - lib/shackles.rb
90
- - LICENSE
91
- - README.md
92
89
  - spec/shackles_spec.rb
93
90
  homepage: http://github.com/instructure/shackles
94
91
  licenses:
95
92
  - MIT
93
+ metadata: {}
96
94
  post_install_message:
97
95
  rdoc_options: []
98
96
  require_paths:
99
97
  - lib
100
98
  required_ruby_version: !ruby/object:Gem::Requirement
101
- none: false
102
99
  requirements:
103
100
  - - ! '>='
104
101
  - !ruby/object:Gem::Version
105
102
  version: '0'
106
103
  required_rubygems_version: !ruby/object:Gem::Requirement
107
- none: false
108
104
  requirements:
109
105
  - - ! '>='
110
106
  - !ruby/object:Gem::Version
111
107
  version: '0'
112
108
  requirements: []
113
109
  rubyforge_project:
114
- rubygems_version: 1.8.23
110
+ rubygems_version: 2.2.0
115
111
  signing_key:
116
- specification_version: 3
112
+ specification_version: 4
117
113
  summary: ActiveRecord database environment switching for slaves and least-privilege
118
114
  test_files:
119
115
  - spec/shackles_spec.rb