Sha256: fb45dae3ff2e1114a965bc43be4c6c24f8121ae26508dc5a48b01926422f7c71

Contents?: true

Size: 720 Bytes

Versions: 22

Compression:

Stored size: 720 Bytes

Contents

#
# Observer module/hooks module, modeled exactly like
# ZenTest::Autotest, in order to ease porting of addons like autotest-screen
#
# In order to use the hooks module, the including class needs to define an
# AVAILABLE_HOOKS constant hash. The rest is handled by the mixin module.
#
module Hooks
  def self.included(target)
    target.class_eval do
      @@hooks = {}
      target::AVAILABLE_HOOKS.each { |hook| @@hooks[hook] = [] }

      def self.add_hook(hook, &block)
        @@hooks[hook] << block
      end

      def self.hook(hook, *args)
        @@hooks[hook].any? do |plugin|
          plugin[self, *args]
        end
      end

      def hook(hook)
        self.class.hook(hook)
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
jstdutil-0.0.2 lib/jstdutil/hooks.rb
jstdutil-0.0.1 lib/jstdutil/hooks.rb