culturecode_stagehand 0.7.12 → 0.7.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e400bbb51d81d1313e506d663ff54a9ef3541ff
4
- data.tar.gz: 0260e41d89133b7f318aa736218990be033410fc
3
+ metadata.gz: 4a6d79d7749da33008302addc5f4ab7b6ef3f53a
4
+ data.tar.gz: b939f07f252406b5ce2c06eba0cbc968d79836d8
5
5
  SHA512:
6
- metadata.gz: 64cccc44d8497b8485e4694b0c8779cb03adc305a3261f34849bf3a7b0ffd8d4597ea757f49bbc2654eeb389578696a7dd75e93d6cc4356fdf812cef73c6995b
7
- data.tar.gz: 36b308306ab666f9f19f46848506794762a7e1a15d0e08df2be24ab98e6dd11ffd739b18bd05cf2f272444a581744d44b13e2d4f22eb655babb5d3d6b50c8d43
6
+ metadata.gz: 9bb90a7ba80ea273602a4d56e8d0d8b22495ed253e9c94444c14d8101c4e2dabbb65e144766decd57a5247ed53b0a7ba8f6b0e3a9c1b67706eed3b45cfce1f2f
7
+ data.tar.gz: 65a6462d3e10ff7ccbb18feb8d437cd409da00eba68901c3522c0149586b53da089e762c510cb712639e66265ad61ee2ca8317bf29653fdc9df21bf39c44fa88
@@ -4,6 +4,11 @@ module Stagehand
4
4
 
5
5
  @@connection_name_stack = [Rails.env.to_sym]
6
6
 
7
+ def each(&block)
8
+ with_connection(Configuration.staging_connection_name, &block)
9
+ with_connection(Configuration.production_connection_name, &block) unless Configuration.single_connection?
10
+ end
11
+
7
12
  def connected_to_production?
8
13
  current_connection_name == Configuration.production_connection_name
9
14
  end
@@ -43,21 +48,17 @@ module Stagehand
43
48
  Rails.logger.debug "Connecting to #{current_connection_name}"
44
49
  connect_to(current_connection_name) if different
45
50
 
46
- yield
51
+ yield connection_name
47
52
  ensure
48
53
  @@connection_name_stack.pop
49
54
  Rails.logger.debug "Restoring connection to #{current_connection_name}"
50
55
  connect_to(current_connection_name) if different
51
56
  end
52
57
 
53
- def set_connection_for_model(model, connection_name)
54
- connect_to(connection_name, model) unless Configuration.ghost_mode?
55
- end
56
-
57
58
  private
58
59
 
59
- def connect_to(connection_name, model = ActiveRecord::Base)
60
- model.establish_connection(connection_name)
60
+ def connect_to(connection_name)
61
+ ActiveRecord::Base.establish_connection(connection_name)
61
62
  end
62
63
 
63
64
  def current_connection_name
@@ -3,8 +3,16 @@ module Stagehand
3
3
  module Model
4
4
  extend ActiveSupport::Concern
5
5
 
6
- included do
7
- Stagehand::Database.set_connection_for_model(self, Configuration.staging_connection_name)
6
+ class_methods do
7
+ def connection
8
+ return super if Configuration.ghost_mode?
9
+
10
+ if Stagehand::Database.connected_to_production?
11
+ Stagehand::Database::StagingProbe.connection
12
+ else
13
+ ActiveRecord::Base.connection
14
+ end
15
+ end
8
16
  end
9
17
  end
10
18
  end
@@ -1,3 +1,3 @@
1
1
  module Stagehand
2
- VERSION = "0.7.12"
2
+ VERSION = "0.7.13"
3
3
  end
@@ -15,33 +15,21 @@ namespace :stagehand do
15
15
  Stagehand::Staging::Synchronizer.sync_all
16
16
  end
17
17
 
18
- desc "Migrate both databases used by stagehand"
19
- task :migrate => :environment do
20
- run_on_both_databases do
21
- Rake::Task['db:migrate'].reenable
22
- Rake::Task['db:migrate'].invoke
18
+ # Enhance the regular tasks to run on both staging and production databases
19
+ def rake_both_databases(task, stagehand_task = task.gsub(':','_'))
20
+ task(stagehand_task => :environment) do
21
+ Stagehand::Database.each do |connection_name|
22
+ puts "#{connection_name}"
23
+ Rake::Task[task].reenable
24
+ Rake::Task[task].invoke
25
+ end
26
+ Rake::Task[task].clear
23
27
  end
24
- Rake::Task['db:migrate'].clear
25
- end
26
28
 
27
- desc "Rollback both databases used by stagehand"
28
- task :rollback => :environment do
29
- run_on_both_databases do
30
- Rake::Task['db:rollback'].reenable
31
- Rake::Task['db:rollback'].invoke
32
- end
33
- Rake::Task['db:rollback'].clear
29
+ # Enhance the original task to run the stagehand_task as a prerequisite
30
+ Rake::Task[task].enhance(["stagehand:#{stagehand_task}"])
34
31
  end
35
- end
36
32
 
37
- def run_on_both_databases(&block)
38
- connections = [Stagehand.configuration.staging_connection_name, Stagehand.configuration.production_connection_name]
39
- connections.compact.uniq.each do |connection_name|
40
- puts "#{connection_name}"
41
- Stagehand::Database.with_connection(connection_name, &block)
42
- end
33
+ rake_both_databases('db:migrate')
34
+ rake_both_databases('db:rollback')
43
35
  end
44
-
45
- # Enhance the regular db:migrate/db:rollback tasks to run the stagehand migration/rollback tasks so both stagehand databases are migrated
46
- Rake::Task['db:migrate'].enhance(['stagehand:migrate'])
47
- Rake::Task['db:rollback'].enhance(['stagehand:rollback'])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: culturecode_stagehand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.12
4
+ version: 0.7.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Jakobsen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-01 00:00:00.000000000 Z
12
+ date: 2016-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails