Class: Bizflow::Lib::CallbackHandler
- Inherits:
-
Object
- Object
- Bizflow::Lib::CallbackHandler
- Defined in:
- lib/bizflow/lib/callback_handler.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
Returns the value of attribute callbacks.
Instance Method Summary collapse
- #callback(name, *args) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ CallbackHandler
constructor
A new instance of CallbackHandler.
- #method_missing(name, *args, &block) ⇒ Object
Constructor Details
#initialize ⇒ CallbackHandler
Returns a new instance of CallbackHandler.
7 8 9 |
# File 'lib/bizflow/lib/callback_handler.rb', line 7 def initialize @callbacks = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
11 12 13 14 |
# File 'lib/bizflow/lib/callback_handler.rb', line 11 def method_missing(name, *args, &block) raise "Callback #{name} registered more times" if @callbacks[name.to_sym] @callbacks[name.to_sym] = block end |
Instance Attribute Details
#callbacks ⇒ Object
Returns the value of attribute callbacks.
5 6 7 |
# File 'lib/bizflow/lib/callback_handler.rb', line 5 def callbacks @callbacks end |
Instance Method Details
#callback(name, *args) ⇒ Object
16 17 18 19 |
# File 'lib/bizflow/lib/callback_handler.rb', line 16 def callback(name, *args) raise "Callback '#{name}' not registered" unless @callbacks[name.to_sym] @callbacks[name.to_sym].call(args[0]) end |
#clear ⇒ Object
21 22 23 |
# File 'lib/bizflow/lib/callback_handler.rb', line 21 def clear @callbacks.clear() end |