module TinyHooks

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.

Constants

HALTING
UNDEFINED_TARGETS
VERSION

Public Class Methods

included(base) click to toggle source

@api private

# 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) click to toggle source

@api private

# 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