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
38
|
# File 'lib/canvas_sync/job_batches/callback.rb', line 10
def perform(definition, event, opts, bid, parent_bid)
return unless VALID_CALLBACKS.include?(event)
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)
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
|