Module: LaGear::ActiveRecord::PublishTriggerable

Defined in:
lib/la_gear/active_record/publish_triggerable.rb

Instance Method Summary collapse

Instance Method Details

#publish_after_commit(routing_key, opts) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/la_gear/active_record/publish_triggerable.rb', line 4

def publish_after_commit(routing_key, opts)
  publish_method = "publish_#{routing_key}"
  la_gear_opts = la_gear_options(opts)
  define_method publish_method do
    message = block_given? ? yield(self) : {}
    Bus.publish(routing_key.to_s, message, la_gear_opts)
  end
  after_commit publish_method, after_commit_options(opts)
end

#send_after_commit(routing_key, opts) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/la_gear/active_record/publish_triggerable.rb', line 14

def send_after_commit(routing_key, opts)
  publish_method = "publish_#{routing_key}"
  la_gear_opts = la_gear_options(opts)
  define_method publish_method do
    message = block_given? ? yield(self) : {}
    Bus.publish_local(routing_key.to_s, message, la_gear_opts)
  end
  after_commit publish_method, after_commit_options(opts)
end

#send_in_after_commit(routing_key, opts, interval) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/la_gear/active_record/publish_triggerable.rb', line 24

def send_in_after_commit(routing_key, opts, interval)
  publish_method = "publish_#{routing_key}"
  la_gear_opts = la_gear_options(opts)
  define_method publish_method do
    message = block_given? ? yield(self) : {}
    Bus.publish_local_in(routing_key.to_s, message, la_gear_opts, interval)
  end
  after_commit publish_method, after_commit_options(opts)
end