123456789_123456789_123456789_123456789_123456789_

Class: Puma::Events

Relationships & Source Files
Inherits: Object
Defined in: lib/puma/events.rb

Overview

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

Class Method Summary

Instance Method Summary

Constructor Details

.newEvents

[ GitHub ]

  
# 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

[ GitHub ]

  
# File 'lib/puma/events.rb', line 16

def fire(hook, *args)
  @hooks[hook].each { |t| t.call(*args) }
end

#fire_on_booted!

[ GitHub ]

  
# File 'lib/puma/events.rb', line 45

def fire_on_booted!
  fire(:on_booted)
end

#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

[ GitHub ]

  
# 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