class Puma::Events

This is an event sink used by `Puma::Server` to handle lifecycle events such as :on_booted, :on_restart, and :on_stopped. Using `Puma::DSL` it is possible to register callback hooks for each event type.

Public Class Methods

new() click to toggle source
# File lib/puma/events.rb, line 11
def initialize
  @hooks = Hash.new { |h,k| h[k] = [] }
end

Public Instance Methods

fire(hook, *args) click to toggle source

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!() click to toggle source
# File lib/puma/events.rb, line 45
def fire_on_booted!
  fire(:on_booted)
end
fire_on_restart!() click to toggle source
# File lib/puma/events.rb, line 49
def fire_on_restart!
  fire(:on_restart)
end
fire_on_stopped!() click to toggle source
# File lib/puma/events.rb, line 53
def fire_on_stopped!
  fire(:on_stopped)
end
on_booted(&block) click to toggle source
# File lib/puma/events.rb, line 33
def on_booted(&block)
  register(:on_booted, &block)
end
on_restart(&block) click to toggle source
# File lib/puma/events.rb, line 37
def on_restart(&block)
  register(:on_restart, &block)
end
on_stopped(&block) click to toggle source
# File lib/puma/events.rb, line 41
def on_stopped(&block)
  register(:on_stopped, &block)
end
register(hook, obj=nil, &blk) click to toggle source

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