Class: Saseo::Publishing::DataChangeMessage

Inherits:
Philotic::Message
  • Object
show all
Defined in:
lib/saseo/publishing/data_change_message.rb

Constant Summary collapse

COMPONENT =
:saseo
MESSAGE_TYPE =
:'saseo.record_audit'

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ DataChangeMessage

Returns a new instance of DataChangeMessage.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/saseo/publishing/data_change_message.rb', line 14

def initialize(version)

  super({})
  @id               = version.id
  @transaction_id   = version.transaction_id
  @table_name       = version.table_name
  @action           = version.action
  @whodunnit        = version.whodunnit
  @action_timestamp = version.action_timestamp

  # ActiveRecord 3 doesn't handle jsonb columns properly
  @old_data         = ensure_json_load version.old_data
  @new_data         = ensure_json_load version.new_data

  @item_id   = @new_data ? @new_data['id'] : @old_data['id']
  @item_uuid = @new_data ? @new_data['uuid'] : @old_data['uuid']

  @philotic_component    = COMPONENT
  @philotic_message_type = MESSAGE_TYPE

end

Instance Method Details

#ensure_json_load(val) ⇒ Object



37
38
39
40
# File 'lib/saseo/publishing/data_change_message.rb', line 37

def ensure_json_load(val)
  return val unless val.is_a? String
  Oj.load val
end