Class: Wal::RecordWatcher::MemoryRecordWatcher
Instance Method Summary
collapse
#on_event
Methods included from Watcher
#on_event, #should_watch_table?, #valid_context_prefix?
Constructor Details
Returns a new instance of MemoryRecordWatcher.
161
162
163
|
# File 'lib/wal/record_watcher.rb', line 161
def initialize(watcher)
@watcher = watcher
end
|
Instance Method Details
#on_begin(event) ⇒ Object
165
166
167
|
# File 'lib/wal/record_watcher.rb', line 165
def on_begin(event)
@records = {}
end
|
#on_commit(_event) ⇒ Object
169
170
171
172
173
174
|
# File 'lib/wal/record_watcher.rb', line 169
def on_commit(_event)
@records
&.values
&.lazy
&.each { |event| @watcher.on_record_changed(event) if event }
end
|
#on_delete(event) ⇒ Object
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
# File 'lib/wal/record_watcher.rb', line 203
def on_delete(event)
if (id = event.primary_key)
@records ||= {}
@records[[event.full_table_name, id]] = case (existing_event = @records[[event.full_table_name, id]])
when InsertEvent
nil
when UpdateEvent
event.with(old: existing_event.old)
else
event
end
end
end
|
#on_insert(event) ⇒ Object
176
177
178
179
180
181
|
# File 'lib/wal/record_watcher.rb', line 176
def on_insert(event)
if (id = event.primary_key)
@records ||= {}
@records[[event.table, id]] = event
end
end
|
#on_update(event) ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/wal/record_watcher.rb', line 183
def on_update(event)
if (id = event.primary_key)
@records ||= {}
@records[[event.full_table_name, id]] = case (existing_event = @records[[event.full_table_name, id]])
when InsertEvent
existing_event.with(new: event.new)
when UpdateEvent
existing_event.with(new: event.new)
else
event
end
end
end
|