module TheHelp::ProvidesCallbacks::ClassMethods
Classes that include ProvidesCallbacks
are extended with these ClassMethods
Protected Instance Methods
_provides_callbacks_callback_defined?(name, check_ancestors: true)
click to toggle source
# File lib/the_help/provides_callbacks.rb, line 69 def _provides_callbacks_callback_defined?(name, check_ancestors: true) _provides_callbacks_defined_callbacks.include?(name.to_sym) || (check_ancestors && _provides_callbacks_superclass_callback_defined?(name)) end
Private Instance Methods
_provides_callbacks_alias_method(without_logging, name)
click to toggle source
# File lib/the_help/provides_callbacks.rb, line 123 def _provides_callbacks_alias_method(without_logging, name) return unless _provides_callbacks_method_defined?(name) alias_method without_logging, name private without_logging end
_provides_callbacks_define_method_with_block(without_logging, &block)
click to toggle source
# File lib/the_help/provides_callbacks.rb, line 116 def _provides_callbacks_define_method_with_block(without_logging, &block) return unless block_given? define_method(without_logging, &block) private without_logging end
_provides_callbacks_define_wrapper(name, without_logging)
click to toggle source
# File lib/the_help/provides_callbacks.rb, line 130 def _provides_callbacks_define_wrapper(name, without_logging) make_public = public_method_defined?(name) define_method(name) do |*args| if defined?(logger) logger.debug("#{self.class.name}/#{__id__} received callback " \ ":#{name}.") end send(without_logging, *args) self end private name unless make_public end
_provides_callbacks_defined_callbacks()
click to toggle source
# File lib/the_help/provides_callbacks.rb, line 99 def _provides_callbacks_defined_callbacks @_provides_callbacks_defined_callbacks ||= Set.new end
_provides_callbacks_method_defined?(name)
click to toggle source
# File lib/the_help/provides_callbacks.rb, line 112 def _provides_callbacks_method_defined?(name) method_defined?(name) || private_method_defined?(name) end
_provides_callbacks_superclass_callback_defined?(name)
click to toggle source
# File lib/the_help/provides_callbacks.rb, line 103 def _provides_callbacks_superclass_callback_defined?(name) ancestors.any? { |ancestor| ancestor.include?(TheHelp::ProvidesCallbacks) && ancestor._provides_callbacks_callback_defined?( name, check_ancestors: false ) } end
callback(name, &block)
click to toggle source
Defines a callback method on the class
Regardless of whether the callback is pointing to an existing instance method or if it is defined via the block argument, the callback will also be wrapped in logging statements that can help you trace the execution path through your code in the event of any anomolies.
@param name [Symbol] The name of the callback. If no block is provided,
then name must be the name of an existing instance method.
@param block [Proc] If a block is provided, the block will act as the
though it is the body of an instance method when the callback is invoked.
@return [self]
# File lib/the_help/provides_callbacks.rb, line 90 def callback(name, &block) _provides_callbacks_defined_callbacks << name.to_sym without_logging = "#{name}_without_logging".to_sym _provides_callbacks_define_method_with_block(without_logging, &block) _provides_callbacks_alias_method(without_logging, name) _provides_callbacks_define_wrapper(name, without_logging) self end