rails-env-switcher 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,8 @@
|
|
1
1
|
module RailsEnvSwitcher::Switcher::ActiveRecord
|
2
2
|
def self.switch_env(old_env, env, options={})
|
3
|
-
if
|
4
|
-
|
5
|
-
|
6
|
-
::ActiveRecord::Base.establish_connection
|
3
|
+
if defined? ActiveRecord
|
4
|
+
ActiveRecord::Base.clear_active_connections!
|
5
|
+
ActiveRecord::Base.establish_connection
|
7
6
|
end
|
8
7
|
end
|
9
8
|
end
|
@@ -1,15 +1,11 @@
|
|
1
1
|
module RailsEnvSwitcher::Switcher::Rails
|
2
2
|
def self.switch_env(old_env, env, options={})
|
3
|
-
if ::Rails.env
|
4
|
-
ENV['RAILS_ENV'] = env
|
5
|
-
::Rails.env = env
|
3
|
+
return if ::Rails.env == env
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
load Rails.root.join('config', 'environments', "#{env}.rb")
|
12
|
-
end
|
5
|
+
ENV['RAILS_ENV'] = ::Rails.env = env
|
6
|
+
Kernel.silence_warnings do
|
7
|
+
Dir[Rails.root.join('config', 'initializers', '*.rb')].each { |file| load file }
|
8
|
+
load Rails.root.join('config', 'environments', "#{env}.rb")
|
13
9
|
end
|
14
10
|
end
|
15
11
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module RailsEnvSwitcher::Switcher::Reloader
|
2
2
|
def self.switch_env(old_env, env, options={})
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
if options[:reload]
|
4
|
+
ActionDispatch::Reloader.cleanup!
|
5
|
+
ActionDispatch::Reloader.prepare!
|
6
6
|
reload!(false) if respond_to?(:reload!)
|
7
7
|
FactoryGirl.reload if defined?(FactoryGirl)
|
8
8
|
end
|
data/lib/rails-env-switcher.rb
CHANGED
@@ -11,6 +11,7 @@ module RailsEnvSwitcher
|
|
11
11
|
switch_env(env, options)
|
12
12
|
yield
|
13
13
|
ensure
|
14
|
+
options.delete(:reload) # not reloading again once we switch back
|
14
15
|
switch_env(old_env, options)
|
15
16
|
end
|
16
17
|
end
|
@@ -22,6 +23,9 @@ module RailsEnvSwitcher
|
|
22
23
|
self.handlers.each do |handler|
|
23
24
|
handler.switch_env(old_env, env, options)
|
24
25
|
end
|
26
|
+
else
|
27
|
+
# Always reload if needed
|
28
|
+
Switcher::Reloader.switch_env(env, env, options)
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-env-switcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.1
|
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:
|
12
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -34,14 +34,14 @@ executables: []
|
|
34
34
|
extensions: []
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
|
-
- lib/rails-env-switcher/switcher/active_record.rb
|
38
37
|
- lib/rails-env-switcher/switcher/copycopter_client.rb
|
39
|
-
- lib/rails-env-switcher/switcher/rails.rb
|
40
38
|
- lib/rails-env-switcher/switcher/mongoid.rb
|
41
39
|
- lib/rails-env-switcher/switcher/bundler.rb
|
40
|
+
- lib/rails-env-switcher/switcher/active_record.rb
|
41
|
+
- lib/rails-env-switcher/switcher/rails.rb
|
42
42
|
- lib/rails-env-switcher/switcher/reloader.rb
|
43
|
-
- lib/rails-env-switcher/switcher.rb
|
44
43
|
- lib/rails-env-switcher/pry.rb
|
44
|
+
- lib/rails-env-switcher/switcher.rb
|
45
45
|
- lib/rails-env-switcher/version.rb
|
46
46
|
- lib/rails-env-switcher.rb
|
47
47
|
- README.md
|
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
67
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.8.
|
68
|
+
rubygems_version: 1.8.25
|
69
69
|
signing_key:
|
70
70
|
specification_version: 3
|
71
71
|
summary: Switch from a Rails environment to another
|