module PubSubModelSync::PublisherConcern

Public Instance Methods

ps_after_publish(_action, _payload) click to toggle source

after delivering data

# File lib/pub_sub_model_sync/publisher_concern.rb, line 17
def ps_after_publish(_action, _payload); end
Also aliased as: ps_after_sync
ps_after_sync(_action, _payload)
Alias for: ps_after_publish
ps_before_publish(_action, _payload) click to toggle source

before delivering data (return :cancel to cancel sync)

# File lib/pub_sub_model_sync/publisher_concern.rb, line 13
def ps_before_publish(_action, _payload); end
Also aliased as: ps_before_sync
ps_before_sync(_action, _payload)
Alias for: ps_before_publish
ps_perform_publish(action = :create) click to toggle source

Permits to perform manually the callback for a specific action @param action (Symbol, default: :create) Only :create|:update|:destroy

# File lib/pub_sub_model_sync/publisher_concern.rb, line 41
def ps_perform_publish(action = :create)
  items = self.class.ps_cache_publish_callbacks.select { |item| item[:actions].include?(action) }
  raise(StandardError, "No callback found for action :#{action}") if items.empty?

  items.each { |item| instance_exec(action, &item[:callback]) }
  self
end
ps_publish(action, data: {}, mapping: [], headers: {}, as_klass: self.class.name) click to toggle source

Delivers a notification via pubsub @param action (Symbol,String) Sample: create|update|save|destroy|<any_other_key> @param mapping? (Array<String>) If present will generate data using the mapping and added to the payload.

Sample: ["id", "full_name:name"]

@param data? (Hash,Symbol,Proc)

Hash: Data to be added to the payload
Symbol: Method name to be called to retrieve payload data (must return a hash value, receives :action name)
Proc: Block to be called to retrieve payload data

@param headers? (Hash,Symbol,Proc): (All available attributes in @Payload.headers)

Hash: Data that will be merged with default header values
Symbol: Method name that will be called to retrieve header values (must return a hash, receives :action name)
Proc: Block to be called to retrieve header values

@param as_klass? (String): Output class name used instead of current class name

# File lib/pub_sub_model_sync/publisher_concern.rb, line 33
def ps_publish(action, data: {}, mapping: [], headers: {}, as_klass: self.class.name)
  p_klass = PubSubModelSync::MessagePublisher
  p_klass.publish_model(self, action, data: data, mapping: mapping, headers: headers, as_klass: as_klass)
end