Module: AfterDo::Instance

Defined in:
lib/after_do.rb

Instance Method Summary collapse

Instance Method Details

#_after_do_execute_callback(block, method, *args) ⇒ Object



118
119
120
121
122
123
124
# File 'lib/after_do.rb', line 118

def _after_do_execute_callback(block, method, *args)
  begin
    block.call *args, self
  rescue Exception => error
    raise CallbackError, "A callback block for method #{method} on the instance #{self} with the following arguments: #{args.join(', ')} defined in the file #{block.source_location[0]} in line #{block.source_location[1]} resulted in the following error: #{error.class}: #{error.message} and this backtrace:\n #{error.backtrace.join("\n")}"
  end
end

#_after_do_execute_callbacks(type, method, *args) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/after_do.rb', line 102

def _after_do_execute_callbacks(type, method, *args)
  callback_classes = self.class.ancestors.select do |klazz|
    _after_do_has_callback_for?(klazz, type, method)
  end
  callback_classes.each do |klazz|
    klazz._after_do_callbacks[type][method].each do |block|
      _after_do_execute_callback(block, method, *args)
    end
  end
end

#_after_do_has_callback_for?(klazz, type, method) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
116
# File 'lib/after_do.rb', line 113

def _after_do_has_callback_for?(klazz, type, method)
  klazz.respond_to?(:_after_do_callbacks) &&
    klazz._after_do_callbacks[type][method]
end