Class: TableSync::Publishing::Message::Base
- Inherits:
-
Object
- Object
- TableSync::Publishing::Message::Base
- Defined in:
- lib/table_sync/publishing/message/base.rb
Instance Attribute Summary collapse
-
#custom_version ⇒ Object
Returns the value of attribute custom_version.
-
#event ⇒ Object
Returns the value of attribute event.
-
#object_class ⇒ Object
Returns the value of attribute object_class.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#original_attributes ⇒ Object
Returns the value of attribute original_attributes.
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.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/table_sync/publishing/message/base.rb', line 12 def initialize(params = {}) self.custom_version = params[:custom_version] self.object_class = params[:object_class] self.original_attributes = params[:original_attributes] self.event = params[:event].to_sym @objects = find_or_init_objects raise TableSync::NoObjectsForSyncError if objects.empty? && TableSync. end |
Instance Attribute Details
#custom_version ⇒ Object
Returns the value of attribute custom_version.
5 6 7 |
# File 'lib/table_sync/publishing/message/base.rb', line 5 def custom_version @custom_version end |
#event ⇒ Object
Returns the value of attribute event.
5 6 7 |
# File 'lib/table_sync/publishing/message/base.rb', line 5 def event @event end |
#object_class ⇒ Object
Returns the value of attribute object_class.
5 6 7 |
# File 'lib/table_sync/publishing/message/base.rb', line 5 def object_class @object_class end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
10 11 12 |
# File 'lib/table_sync/publishing/message/base.rb', line 10 def objects @objects end |
#original_attributes ⇒ Object
Returns the value of attribute original_attributes.
5 6 7 |
# File 'lib/table_sync/publishing/message/base.rb', line 5 def original_attributes @original_attributes end |
Instance Method Details
#data ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/table_sync/publishing/message/base.rb', line 47 def data TableSync::Publishing::Data::Objects.new( objects:, event:, custom_version:, ).construct end |
#empty? ⇒ Boolean
31 32 33 |
# File 'lib/table_sync/publishing/message/base.rb', line 31 def empty? objects.empty? end |
#find_or_init_objects ⇒ Object
35 36 37 38 39 |
# File 'lib/table_sync/publishing/message/base.rb', line 35 def find_or_init_objects TableSync::Publishing::Helpers::Objects.new( object_class:, original_attributes:, event:, ).construct_list end |
#message_params ⇒ Object
MESSAGE PARAMS
43 44 45 |
# File 'lib/table_sync/publishing/message/base.rb', line 43 def params.merge(data:) end |
#model_naming ⇒ Object
73 74 75 |
# File 'lib/table_sync/publishing/message/base.rb', line 73 def model_naming TableSync.publishing_adapter.model_naming(objects.first.object_class) end |
#notify! ⇒ Object
NOTIFY
63 64 65 66 67 68 69 70 71 |
# File 'lib/table_sync/publishing/message/base.rb', line 63 def notify! TableSync::Instrument.notify( table: model_naming.table, schema: model_naming.schema, event:, direction: :publish, count: objects.count, ) end |
#params ⇒ Object
:nocov:
56 57 58 |
# File 'lib/table_sync/publishing/message/base.rb', line 56 def params raise NotImplementedError end |
#publish ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/table_sync/publishing/message/base.rb', line 23 def publish return if original_attributes.blank? Rabbit.publish(**) notify! end |