Class: TableSync::Receiving::Handler
- Inherits:
-
Rabbit::EventHandler
- Object
- Rabbit::EventHandler
- TableSync::Receiving::Handler
- Extended by:
- DSL
- Defined in:
- lib/table_sync/receiving/handler.rb
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(message) ⇒ Handler
constructor
A new instance of Handler.
Methods included from DSL
Constructor Details
#initialize(message) ⇒ Handler
Returns a new instance of Handler.
9 10 11 12 13 14 15 |
# File 'lib/table_sync/receiving/handler.rb', line 9 def initialize() super self.event = .data[:event] self.model = .data[:model] self.version = .data[:version] end |
Instance Attribute Details
#event ⇒ Object
Returns the value of attribute event.
7 8 9 |
# File 'lib/table_sync/receiving/handler.rb', line 7 def event @event end |
#model ⇒ Object
Returns the value of attribute model.
7 8 9 |
# File 'lib/table_sync/receiving/handler.rb', line 7 def model @model end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/table_sync/receiving/handler.rb', line 6 def version @version end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/table_sync/receiving/handler.rb', line 17 def call configs.each do |config| next unless config.allow_event?(event) data = processed_data(config) next if data.empty? version_key = config.version_key(data:) data.each { |row| row[version_key] = version } target_keys = config.target_keys(data:) validate_data(data, target_keys:) data.sort_by! { |row| row.values_at(*target_keys).map { |value| sort_key(value) } } params = { data:, target_keys:, version_key: } if event == :update params[:default_values] = config.default_values(data:) end config.wrap_receiving(event:, **params) do perform(config, params) end end end |