Class: TableSync::Publishing::Message::Base
- Inherits:
-
Object
- Object
- TableSync::Publishing::Message::Base
- Includes:
- Tainbox
- Defined in:
- lib/table_sync/publishing/message/base.rb
Instance Attribute Summary collapse
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
Instance Method Summary collapse
- #data ⇒ Object
- #empty? ⇒ Boolean
- #find_or_init_objects ⇒ Object
-
#initialize(params) ⇒ Base
constructor
A new instance of Base.
-
#message_params ⇒ Object
MESSAGE PARAMS.
- #model_naming ⇒ Object
-
#notify! ⇒ Object
NOTIFY.
-
#params ⇒ Object
:nocov:.
- #publish ⇒ Object
Constructor Details
#initialize(params) ⇒ Base
Returns a new instance of Base.
13 14 15 16 17 18 19 |
# File 'lib/table_sync/publishing/message/base.rb', line 13 def initialize(params) super(params) @objects = find_or_init_objects raise TableSync::NoObjectsForSyncError if objects.empty? && TableSync. end |
Instance Attribute Details
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
7 8 9 |
# File 'lib/table_sync/publishing/message/base.rb', line 7 def objects @objects end |
Instance Method Details
#data ⇒ Object
45 46 47 48 49 |
# File 'lib/table_sync/publishing/message/base.rb', line 45 def data TableSync::Publishing::Data::Objects.new( objects: objects, event: event, ).construct end |
#empty? ⇒ Boolean
29 30 31 |
# File 'lib/table_sync/publishing/message/base.rb', line 29 def empty? objects.empty? end |
#find_or_init_objects ⇒ Object
33 34 35 36 37 |
# File 'lib/table_sync/publishing/message/base.rb', line 33 def find_or_init_objects TableSync::Publishing::Helpers::Objects.new( object_class: object_class, original_attributes: original_attributes, event: event, ).construct_list end |
#message_params ⇒ Object
MESSAGE PARAMS
41 42 43 |
# File 'lib/table_sync/publishing/message/base.rb', line 41 def params.merge(data: data) end |
#model_naming ⇒ Object
69 70 71 |
# File 'lib/table_sync/publishing/message/base.rb', line 69 def model_naming TableSync.publishing_adapter.model_naming(objects.first.object_class) end |
#notify! ⇒ Object
NOTIFY
59 60 61 62 63 64 65 66 67 |
# File 'lib/table_sync/publishing/message/base.rb', line 59 def notify! TableSync::Instrument.notify( table: model_naming.table, schema: model_naming.schema, event: event, direction: :publish, count: objects.count, ) end |
#params ⇒ Object
:nocov:
52 53 54 |
# File 'lib/table_sync/publishing/message/base.rb', line 52 def params raise NotImplementedError end |
#publish ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/table_sync/publishing/message/base.rb', line 21 def publish return if original_attributes.blank? Rabbit.publish() notify! end |