culturecode_stagehand 0.7.14 → 0.7.16

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: ac363341da8677b3c1cfd520613c84e0867f3ad2
4
- data.tar.gz: 9589806d9dd238748cc953f54f411ef442a8d63c
3
+ metadata.gz: 38286b5f9333c0db58872b75ebb6bbded9cfa4da
4
+ data.tar.gz: 26f901f9f273e6622a866f92da44c7a8f65e8b9d
5
5
  SHA512:
6
- metadata.gz: 54f5ea80bac184c901919d16e9832a2c7b09b208916ab92f744d783dd9079d8af88609e92b568bbe705a75f20ada6d708caf6bebf5db15c07681f2cc437b3c77
7
- data.tar.gz: bdac04efe1e754db2a006a6bb86ec6ef09e192d00066ba969f6dd8260a7b54daf67b8d777cac8a0e574528188e27c607cadc1d0c5b2a224723893680e7d4b817
6
+ metadata.gz: dd4a38e8b374c151d42818b77b7403f96917c1730330dd94b767fea1e38aa3d8ff74d1804fbe84c22e5d87cd9eafc0fd65a3e337d19de325cb0fb8a8664c3789
7
+ data.tar.gz: 100c6686c5cdac790b96c60c13f1c56db9814a839f39bc196b5d3da3a53887caff9f559b2f5ca2db054e4031a0fdfdbe433f56e99664c6c7d887b3d03728115a
@@ -7,7 +7,7 @@ module Stagehand
7
7
 
8
8
  def self.capture(subject_record = nil, &block)
9
9
  start_operation = start_commit(subject_record)
10
- block.call
10
+ block.call(start_operation)
11
11
  return end_commit(start_operation)
12
12
  rescue => e
13
13
  end_commit(start_operation)
@@ -32,12 +32,12 @@ module Stagehand
32
32
  def self.start_commit(subject_record)
33
33
  start_operation = CommitEntry.start_operations.new
34
34
 
35
- if subject_record
36
- start_operation.record_id = subject_record.id
37
- start_operation.table_name = subject_record.class.table_name
35
+ # Make it easy to set the subject for the duration of the commit block
36
+ def start_operation.subject=(record)
37
+ update_attributes!(:record_id => record.try(:id), :table_name => record.class.try(:table_name))
38
38
  end
39
39
 
40
- start_operation.save
40
+ start_operation.subject = subject_record
41
41
 
42
42
  return start_operation.reload # Reload to ensure session is set
43
43
  end
@@ -91,6 +91,10 @@ module Stagehand
91
91
  def entries
92
92
  CommitEntry.where(:id => @start_id..@end_id).where(:commit_id => id)
93
93
  end
94
+
95
+ def subject
96
+ entries.sort_by(&:id).first.record
97
+ end
94
98
  end
95
99
  end
96
100
 
@@ -70,7 +70,7 @@ module Stagehand
70
70
  end
71
71
 
72
72
  def record
73
- @record ||= delete_operation? ? build_deleted_record : record_class.find_by_id(record_id) if content_operation?
73
+ @record ||= delete_operation? ? build_deleted_record : record_class.find_by_id(record_id) if record_id?
74
74
  end
75
75
 
76
76
  def control_operation?
@@ -135,11 +135,16 @@ module Stagehand
135
135
 
136
136
  def self.build_missing_model(table_name)
137
137
  raise MissingTable, "Can't find table specified in entry: #{table_name}" unless Database.staging_connection.tables.include?(table_name)
138
- Object.const_set(table_name.classify, Class.new(ActiveRecord::Base))
138
+ klass = Class.new(ActiveRecord::Base) { self.table_name = table_name }
139
+ DummyClass.const_set(table_name.classify, klass)
139
140
  end
140
141
  end
141
142
  end
142
143
 
144
+ # DUMMY CLASSES
145
+
146
+ module DummyClass; end
147
+
143
148
  # EXCEPTIONS
144
149
  class IndeterminateRecordClass < StandardError; end
145
150
  class MissingTable < StandardError; end
@@ -1,3 +1,3 @@
1
1
  module Stagehand
2
- VERSION = "0.7.14"
2
+ VERSION = "0.7.16"
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.7.14
4
+ version: 0.7.16
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-31 00:00:00.000000000 Z
12
+ date: 2016-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails