Module: ActorSync::ClassMethods

Defined in:
lib/actor_sync.rb

Instance Method Summary collapse

Instance Method Details

#actor_sync(destination, opts = {}) ⇒ Object

Generate an instance method to be passed to after_commit Call class method after_commit & pass earlier defined instance method.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/actor_sync.rb', line 26

def actor_sync(destination, opts = {})
  callback_types = %i(create update destroy)

  callback_types.each do |callback_name|
    method_name = "export_to_#{destination}_on_#{callback_name}"

    instance_eval do
      define_method method_name  do
        opts[:callback_type] = callback_name
        Sync.new(self, destination, opts).call
      end
    end

    class_eval <<-METHODS, __FILE__, __LINE__ + 1
      after_commit :#{method_name}, on: :#{callback_name}
    METHODS
  end
end