Module: TinyHooks
- Defined in:
- lib/tiny_hooks.rb,
lib/tiny_hooks/version.rb
Overview
TinyHooks is the gem to easily define hooks. ‘extend` this module and now you can define hooks with `define_hook` method. See the test file for more detailed usage.
Defined Under Namespace
Modules: ClassMethods Classes: Error, PrivateError, TargetError
Constant Summary collapse
- VERSION =
'2.0.0'
Class Method Summary collapse
- .included(base) ⇒ Object private
- .with_halting(terminator, *args, **kwargs, &block) ⇒ Object private
Class Method Details
.included(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 24 25 26 27 28 29 |
# File 'lib/tiny_hooks.rb', line 21 def self.included(base) base.class_eval do @_originals = {} @_class_originals = {} @_targets = UNDEFINED_TARGETS @_public_only = false end base.extend ClassMethods end |
.with_halting(terminator, *args, **kwargs, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tiny_hooks.rb', line 32 def self.with_halting(terminator, *args, **kwargs, &block) hook_result = nil abort_result = catch :abort do hook_result = instance_exec(*args, **kwargs, &block) true end return HALTING if abort_result.nil? && terminator == :abort return HALTING if hook_result == false && terminator == :return_false hook_result end |