Class: Bizflow::Lib::CallbackHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/bizflow/lib/callback_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallbackHandler

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

#callbacksObject

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

#clearObject



21
22
23
# File 'lib/bizflow/lib/callback_handler.rb', line 21

def clear
  @callbacks.clear()
end