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.3.13 lib/jstdutil/hooks.rb
jstdutil-0.3.12 lib/jstdutil/hooks.rb
jstdutil-0.3.11 lib/jstdutil/hooks.rb
jstdutil-0.3.10 lib/jstdutil/hooks.rb
jstdutil-0.3.9 lib/jstdutil/hooks.rb
jstdutil-0.3.8 lib/jstdutil/hooks.rb
jstdutil-0.3.7 lib/jstdutil/hooks.rb
jstdutil-0.3.6 lib/jstdutil/hooks.rb
jstdutil-0.3.5 lib/jstdutil/hooks.rb
jstdutil-0.3.4 lib/jstdutil/hooks.rb
jstdutil-0.3.3 lib/jstdutil/hooks.rb
jstdutil-0.3.2 lib/jstdutil/hooks.rb
jstdutil-0.3.1 lib/jstdutil/hooks.rb
jstdutil-0.3.0 lib/jstdutil/hooks.rb
jstdutil-0.2.2 lib/jstdutil/hooks.rb
jstdutil-0.2.1 lib/jstdutil/hooks.rb
jstdutil-0.2.0 lib/jstdutil/hooks.rb
jstdutil-0.1.2 lib/jstdutil/hooks.rb
jstdutil-0.1.1 lib/jstdutil/hooks.rb
jstdutil-0.1.0 lib/jstdutil/hooks.rb