Class: Puma::Events
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/puma/events.rb |
Overview
Class Method Summary
- .new ⇒ Events constructor
Instance Method Summary
- #after_booted(&block)
- #after_stopped(&block)
- #before_restart(&block)
-
#fire(hook, *args)
Fire callbacks for the named hook.
- #fire_after_booted!
- #fire_after_stopped!
- #fire_before_restart!
-
#register(hook, obj = nil, &blk)
Register a callback for a given hook.
Constructor Details
.new ⇒ Events
# File 'lib/puma/events.rb', line 11
def initialize @hooks = Hash.new { |h,k| h[k] = [] } end
Instance Method Details
#after_booted(&block)
[ GitHub ]# File 'lib/puma/events.rb', line 33
def after_booted(&block) register(:after_booted, &block) end
#after_stopped(&block)
[ GitHub ]# File 'lib/puma/events.rb', line 41
def after_stopped(&block) register(:after_stopped, &block) end
#before_restart(&block)
[ GitHub ]# File 'lib/puma/events.rb', line 37
def before_restart(&block) register(:before_restart, &block) end
#fire(hook, *args)
Fire callbacks for the named hook
# File 'lib/puma/events.rb', line 16
def fire(hook, *args) @hooks[hook].each { |t| t.call(*args) } end
#fire_after_booted!
[ GitHub ]# File 'lib/puma/events.rb', line 45
def fire_after_booted! fire(:after_booted) end
#fire_after_stopped!
[ GitHub ]# File 'lib/puma/events.rb', line 53
def fire_after_stopped! fire(:after_stopped) end
#fire_before_restart!
[ GitHub ]# File 'lib/puma/events.rb', line 49
def fire_before_restart! fire(:before_restart) end
#register(hook, obj = nil, &blk)
Register a callback for a given hook
# File 'lib/puma/events.rb', line 21
def register(hook, obj=nil, &blk) if obj and blk raise "Specify either an object or a block, not both" end h = obj || blk @hooks[hook] << h h end