Module: Hooks
- Included in:
- Bushido::Envs
- Defined in:
- lib/hooks.rb
Constant Summary collapse
- @@hooks =
{}
Instance Method Summary collapse
Instance Method Details
#fire(data, *events) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hooks.rb', line 4 def fire(data, *events) #puts "Hooks: #{@@hooks.inspect}" #puts "Events: #{events.inspect}" #puts "\twith data: #{data.inspect}" unless @@hooks[:global].nil? @@hooks[:global].call(data, 'global') end if events.length > 0 events.each do |event| #print "Checking for event: #{event} in hooks..." if @@hooks[event].nil? #puts "not found, ignoring." else #puts "found, firing!" @@hooks[event].call(data, event) end end end end |
#listen(*events, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hooks.rb', line 25 def listen *events, &block #puts "Listening for #{events.inspect}" if events.empty? and block_given? @@hooks[:global] = block elsif !events.nil? and block_given? events.each do |event| @@hooks[event] = block end end end |