9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/canvas_sync/job_batches/callback.rb', line 9
def perform(definition, event, opts, bid, parent_bid)
return unless VALID_CALLBACKS.include?(event.to_sym)
method = nil
target = :instance
clazz = definition
if clazz.is_a?(String)
if clazz.include?('#')
clazz, method = clazz.split("#")
elsif clazz.include?('.')
clazz, method = clazz.split(".")
target = :class
end
end
method ||= "on_#{event}"
status = Batch::Status.new(bid)
if clazz && object = Object.const_get(clazz)
target = target == :instance ? object.new : object
if target.respond_to?(method, true)
target.send(method, status, opts.with_indifferent_access)
else
Batch.logger.warn("Invalid callback method #{definition} - #{target.to_s} does not respond to #{method}")
end
else
Batch.logger.warn("Invalid callback method #{definition} - Class #{clazz} not found")
end
end
|