summaryrefslogtreecommitdiffstats
path: root/test/lib/spec/callback/callback_container.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-08-23 01:17:33 -0500
committerLuke Kanies <luke@madstop.com>2007-08-23 01:17:33 -0500
commitd59315a07a8a01ca65952d8e8fe9d2f1bb84d30e (patch)
tree8e2470f271c8c6e622f0aef3fd5a2f01502d8305 /test/lib/spec/callback/callback_container.rb
parent5601ecf75d3854a66d087a108e1b06885fa2be12 (diff)
downloadpuppet-d59315a07a8a01ca65952d8e8fe9d2f1bb84d30e.tar.gz
puppet-d59315a07a8a01ca65952d8e8fe9d2f1bb84d30e.tar.xz
puppet-d59315a07a8a01ca65952d8e8fe9d2f1bb84d30e.zip
Adding the second half of the rspec upgrade -- apparently the "git add" thing I used did not remove the old files, only add the new ones.
Diffstat (limited to 'test/lib/spec/callback/callback_container.rb')
-rw-r--r--test/lib/spec/callback/callback_container.rb60
1 files changed, 0 insertions, 60 deletions
diff --git a/test/lib/spec/callback/callback_container.rb b/test/lib/spec/callback/callback_container.rb
deleted file mode 100644
index 24d4c0ced..000000000
--- a/test/lib/spec/callback/callback_container.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-module Callback
- class CallbackContainer
- def initialize
- @callback_registry = Hash.new do |hash, key|
- hash[key] = Array.new
- end
- end
-
- # Defines the callback with the key in this container.
- def define(key, callback_proc=nil, &callback_block)
- callback = extract_callback(callback_block, callback_proc) do
- raise "You must define the callback that accepts the call method."
- end
- @callback_registry[key] << callback
- callback
- end
-
- # Undefines the callback with the key in this container.
- def undefine(key, callback_proc)
- callback = extract_callback(callback_proc) do
- raise "You may only undefine callbacks that use the call method."
- end
- @callback_registry[key].delete callback
- callback
- end
-
- # Notifies the callbacks for the key. Arguments may be passed.
- # An error handler may be passed in as a block. If there is an error, the block is called with
- # error object as an argument.
- # An array of the return values of the callbacks is returned.
- def notify(key, *args, &error_handler)
- @callback_registry[key].collect do |callback|
- begin
- callback.call(*args)
- rescue Exception => e
- yield(e) if error_handler
- end
- end
- end
-
- # Clears all of the callbacks in this container.
- def clear
- @callback_registry.clear
- end
-
- protected
- def extract_callback(first_choice_callback, second_choice_callback = nil)
- callback = nil
- if first_choice_callback
- callback = first_choice_callback
- elsif second_choice_callback
- callback = second_choice_callback
- end
- unless callback.respond_to? :call
- yield
- end
- return callback
- end
- end
-end