culturecode_stagehand 0.4.0 → 0.4.1

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: cd5f6596af77820e4b0fda648cf3a575cef70dd8
4
- data.tar.gz: 73711aa60b690c1a9a7715d5ce26934d79e7727f
3
+ metadata.gz: 0e34f8b1144de550fdbf2d4cf1395b1ac0596d6a
4
+ data.tar.gz: 49ce2b899b0a202e7dae920ee831d7b0f43502a0
5
5
  SHA512:
6
- metadata.gz: 9b685a7c6bd6f6c8638c86f8ff3a316ad2147942b7dcaa378daea28fbc31421cce4105097ac1a3a418d8a6639891e107c5663ee9a5177bdb25770f2d3cd555ac
7
- data.tar.gz: 7f629766d1d1af995dc0870bf15bdc6a2c04c96105859cc5cdc4388cb104c4be11b7f0df4c17987f1b8e54a1fd6447e6847fd792196e346ee8f49da17a558cbe
6
+ metadata.gz: 4b5f80d47ab450ce86ff6a0d4e0e31c517486a7dd67a2cda007e2da64631f90d4e30113ecd2462a212716cbb992bfc7882de830bc239006b0a94afd7aaba64fc
7
+ data.tar.gz: a045c77ac6cdb29ff73c86f789bc0dafd43722c056911259af48351ee8d14f80f1a35c800af935349d2c51733efcca348e9643e626a1785b0177141a49e0fd3c
@@ -12,12 +12,20 @@ module Stagehand
12
12
  current_connection_name == Configuration.staging_connection_name
13
13
  end
14
14
 
15
+ def production_connection
16
+ ProductionProbe.connection
17
+ end
18
+
15
19
  def staging_connection
16
20
  StagingProbe.connection
17
21
  end
18
22
 
19
- def production_connection
20
- ProductionProbe.connection
23
+ def production_database_name
24
+ database_name(Configuration.production_connection_name)
25
+ end
26
+
27
+ def staging_database_name
28
+ database_name(Configuration.staging_connection_name)
21
29
  end
22
30
 
23
31
  def with_connection(connection_name)
@@ -48,6 +56,9 @@ module Stagehand
48
56
  @@connection_name_stack.last
49
57
  end
50
58
 
59
+ def database_name(connection_name)
60
+ Rails.configuration.database_configuration[connection_name.to_s]['database']
61
+ end
51
62
 
52
63
  # CLASSES
53
64
 
@@ -50,10 +50,16 @@ module Stagehand
50
50
  return keys.present? ? where(sql.join(' OR '), *interpolates) : none
51
51
  end
52
52
 
53
- def self.infer_class(table_name)
54
- klass = ActiveRecord::Base.descendants.detect {|klass| klass.table_name == table_name && klass != Stagehand::Production::Record }
55
- klass ||= table_name.classify.constantize # Try loading the class if it isn't loaded yet
53
+ def self.infer_class(table_name, record_id = nil)
54
+ classes = ActiveRecord::Base.descendants.select {|klass| klass.table_name == table_name }
55
+ classes.delete(Stagehand::Production::Record)
56
+ root_class = classes.first || table_name.classify.constantize # Try loading the class if it isn't loaded yet
56
57
 
58
+ if record_id && record = root_class.find_by_id(record_id)
59
+ klass = record.class
60
+ end
61
+
62
+ return klass || root_class
57
63
  rescue NameError
58
64
  raise(IndeterminateRecordClass, "Can't determine class from table name: #{table_name}")
59
65
  end
@@ -103,7 +109,7 @@ module Stagehand
103
109
  end
104
110
 
105
111
  def record_class
106
- @record_class ||= self.class.infer_class(table_name)
112
+ @record_class ||= self.class.infer_class(table_name, record_id)
107
113
  end
108
114
 
109
115
  private
@@ -1,3 +1,3 @@
1
1
  module Stagehand
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Jakobsen