Class: Puma::Events
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/puma/events.rb |
Overview
Class Method Summary
- .new ⇒ Events constructor
Instance Method Summary
-
#fire(hook, *args)
Fire callbacks for the named hook.
- #fire_on_booted!
- #fire_on_restart!
- #fire_on_stopped!
- #on_booted(&block)
- #on_restart(&block)
- #on_stopped(&block)
-
#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
#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_on_booted!
[ GitHub ]#fire_on_restart!
[ GitHub ]# File 'lib/puma/events.rb', line 49
def fire_on_restart! fire(:on_restart) end
#fire_on_stopped!
[ GitHub ]# File 'lib/puma/events.rb', line 53
def fire_on_stopped! fire(:on_stopped) end
#on_booted(&block)
[ GitHub ]# File 'lib/puma/events.rb', line 33
def on_booted(&block) register(:on_booted, &block) end
#on_restart(&block)
[ GitHub ]# File 'lib/puma/events.rb', line 37
def on_restart(&block) register(:on_restart, &block) end
#on_stopped(&block)
[ GitHub ]# File 'lib/puma/events.rb', line 41
def on_stopped(&block) register(:on_stopped, &block) 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