culturecode_stagehand 0.12.1 → 0.12.2

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: 1e520882c8b93a387eaf5be62f54f978efef01ed
4
- data.tar.gz: b3f249ffbcac57b013e587f93d915c6f75515710
3
+ metadata.gz: '091f0329dd66eeb808a7a8efc8ee5741adf0b784'
4
+ data.tar.gz: 1f1fb675ec96bde1b1eba99dee37e32589bf3833
5
5
  SHA512:
6
- metadata.gz: 7d2555054b079e1278b584a9d5589f485041ac4125eaef11731461a7ec546c16468fef0ea23cdfd9993d55be8b8a19fb88f3e0dc3d1691ce58459b16b407cf50
7
- data.tar.gz: 7206daab7937c07059e28226d88f582323dd171ac543ed4b739143a8439a7df2b9db8c9bfff9630a450441e47c54756d51fe8541075bc1209fec6355deb84d7f
6
+ metadata.gz: f887b8666704eea9831568b093dfbcdbe7a53662f735b97fd07370563e9885ddcddf46d2a7aa070930a628e032ead9b9c2f65256723773875421a24927f129af
7
+ data.tar.gz: b0697843d0c5f03a3400e34114aa55448ed36c8e19f9a7ede070e2b9aa0d072ea353574703a2eb4be422fcdc761980f14de1c2a1fbb0a25061d8e8a63b331269
@@ -1,14 +1,6 @@
1
1
  ActiveRecord::Base.class_eval do
2
2
  # SYNC CALLBACKS
3
- define_callbacks :sync
4
-
5
- def self.before_sync(method, options = {})
6
- set_callback :sync, :before, method, options
7
- end
8
-
9
- def self.after_sync(method, options = {})
10
- set_callback :sync, :after, method, options
11
- end
3
+ define_model_callbacks :sync, :sync_as_subject, :sync_as_affected
12
4
 
13
5
  # SYNC STATUS
14
6
  def self.inherited(subclass)
@@ -146,6 +146,10 @@ module Stagehand
146
146
  end
147
147
  end
148
148
 
149
+ def subject_entries
150
+ cache(:subject_entries) { CommitEntry.matching(@subject) }
151
+ end
152
+
149
153
  private
150
154
 
151
155
  def grouped_required_confirmation_entries
@@ -33,7 +33,7 @@ module Stagehand
33
33
 
34
34
  Rails.logger.info "Syncing"
35
35
  iterate_autosyncable_entries do |entry|
36
- sync_entries(entry)
36
+ sync_entry(entry, :callbacks => :sync)
37
37
  synced_count += 1
38
38
  deleted_count += CommitEntry.matching(entry).delete_all
39
39
  break if synced_count == limit
@@ -51,7 +51,7 @@ module Stagehand
51
51
  break unless entries.present?
52
52
 
53
53
  latest_entries = entries.uniq(&:key)
54
- sync_entries(latest_entries)
54
+ latest_entries.each {|entry| sync_entry(entry, :callbacks => :sync) }
55
55
  Rails.logger.info "Synced #{latest_entries.count} entries"
56
56
 
57
57
  deleted_count = CommitEntry.matching(latest_entries).delete_all
@@ -66,7 +66,14 @@ module Stagehand
66
66
 
67
67
  def sync_checklist(checklist)
68
68
  Database.transaction do
69
- sync_entries(checklist.syncing_entries)
69
+ checklist.syncing_entries.each do |entry|
70
+ if checklist.subject_entries.include?(entry)
71
+ sync_entry(entry, :callbacks => [:sync, :sync_as_subject])
72
+ else
73
+ sync_entry(entry, :callbacks => [:sync, :sync_as_affected])
74
+ end
75
+ end
76
+
70
77
  CommitEntry.delete(checklist.affected_entries)
71
78
  end
72
79
  end
@@ -106,25 +113,19 @@ module Stagehand
106
113
  return entries
107
114
  end
108
115
 
109
- def sync_entries(entries)
116
+ def sync_entry(entry, callbacks: [])
110
117
  raise SchemaMismatch unless schemas_match?
111
118
 
112
- entries = Array.wrap(entries)
113
-
114
- entries.each do |entry|
115
- run_sync_callbacks(entry) do
116
- Rails.logger.info "Synchronizing #{entry.table_name} #{entry.record_id}" if entry.content_operation?
117
- if Configuration.single_connection?
118
- next # Avoid deadlocking if the databases are the same
119
- elsif entry.delete_operation?
120
- Production.delete(entry)
121
- elsif entry.save_operation?
122
- Production.save(entry)
123
- end
119
+ run_sync_callbacks(entry, callbacks) do
120
+ Rails.logger.info "Synchronizing #{entry.table_name} #{entry.record_id}" if entry.content_operation?
121
+ if Configuration.single_connection?
122
+ next # Avoid deadlocking if the databases are the same
123
+ elsif entry.delete_operation?
124
+ Production.delete(entry)
125
+ elsif entry.save_operation?
126
+ Production.save(entry)
124
127
  end
125
128
  end
126
-
127
- return entries.length
128
129
  end
129
130
 
130
131
  def schemas_match?
@@ -133,8 +134,13 @@ module Stagehand
133
134
  return schemas_match
134
135
  end
135
136
 
136
- def run_sync_callbacks(entry, &block)
137
- entry.record.run_callbacks(:sync, &block) if entry.record
137
+ def run_sync_callbacks(entry, callbacks, &block)
138
+ callbacks = Array.wrap(callbacks).dup
139
+ return block.call unless entry.record && callbacks.present?
140
+
141
+ entry.record.run_callbacks(callbacks.shift) do
142
+ run_sync_callbacks(entry, callbacks, &block)
143
+ end
138
144
  end
139
145
  end
140
146
  end
@@ -1,3 +1,3 @@
1
1
  module Stagehand
2
- VERSION = "0.12.1"
2
+ VERSION = "0.12.2"
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.12.1
4
+ version: 0.12.2
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: 2017-01-10 00:00:00.000000000 Z
12
+ date: 2017-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails