Class: Evento::Orchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/evento/orchestrator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, options = {}) ⇒ Orchestrator

Returns a new instance of Orchestrator.



7
8
9
10
11
# File 'lib/evento/orchestrator.rb', line 7

def initialize(klass, options = {})
  @klass     = klass
  @options   = options
  @extractor = nil
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/evento/orchestrator.rb', line 5

def klass
  @klass
end

Instance Method Details

#after_audit_trail_commit(name, &block) ⇒ Object



18
19
20
21
# File 'lib/evento/orchestrator.rb', line 18

def after_audit_trail_commit(name, &block)
  association = extractor.extract_audit_trail_association(extract_audit_trail_options)
  after_association_commit(association, name, &block)
end

#after_transaction_log_commit(name, &block) ⇒ Object



13
14
15
16
# File 'lib/evento/orchestrator.rb', line 13

def after_transaction_log_commit(name, &block)
  association = extractor.extract_transaction_log_association
  after_association_commit(association, name, &block)
end

#define_event_methods_on(target_klass, options = {}, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/evento/orchestrator.rb', line 23

def define_event_methods_on(target_klass, options = {}, &block)
  extractor.extract_events(state_machine: options[:state_machine], devise: options[:devise])
           .reject { |event_name| target_klass.method_defined?(event_name) }
           .each do |event_name|
    target_klass.send(:define_method, event_name, &block)
  end

  return unless options[:life_cycle]

  %i[create destroy update save].each do |event_name|
    target_klass.send(:define_method, event_name, &block) unless target_klass.method_defined?(event_name)
  end
end

#override_devise_notification(&block) ⇒ Object



37
38
39
40
# File 'lib/evento/orchestrator.rb', line 37

def override_devise_notification(&block)
  # As this is an override, ignore checking if it exists
  klass.define_method(:send_devise_notification, block)
end