Module: Pheromone::Publishable::ClassMethods

Defined in:
lib/pheromone/publishable.rb

Overview

class methods for the model including Publishable

Instance Method Summary collapse

Instance Method Details

#publish(message_options) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pheromone/publishable.rb', line 39

def publish(message_options)
  errors = Pheromone::Validators::OptionsValidator.new(
    message_options
  ).validate
  raise Pheromone::Exceptions::InvalidPublishOptions.new(errors) unless errors.empty?
  __send__(
    :after_commit,
    proc { dispatch_messages(message_options: message_options, current_event: :create) },
    on: :create
  )
  __send__(
    :after_commit,
    proc { dispatch_messages(message_options: message_options, current_event: :update) },
    on: :update
  )
end