Repository: puma/puma
File: lib/puma/dsl.rb (Ruby)

Code before:
    #   directory '/u/apps/lolcat'
    def directory(dir)
      @options[:directory] = dir.to_s
    end

    # Preload the application before starting the workers; this conflicts with
    # phased restart feature. On by default if your app uses more than 1 worker.
    #
    # @note Cluster mode only.
    # @example
    #   preload_app!
    def preload_app!(answer=true)
      @options[:preload_app] = answer
    end

    # Use +obj+ or +block+ as the low level error handler. This allows the
    # configuration file to change the default error on the server.
    #
    # @example
    #   lowlevel_error_handler do |err|
    #     [200, {}, ["error page"]]
    #   end
    def lowlevel_error_handler(obj=nil, &block)
      obj ||= block
      raise "Provide either a #call'able or a block" unless obj
      @options[:lowlevel_error_handler] = obj
    end

    # This option is used to allow your app and its gems to be
    # properly reloaded when not using preload.
    #
    # When set, if Puma detects that it's been invoked in the
    # context of Bundler, it will cleanup the environment and
    # re-run itself outside the Bundler environment, but directly
    # using the files that Bundler has setup.
    #
    # This means that Puma is now decoupled from your Bundler
    # context and when each worker loads, it will be loading a
    # new Bundler context and thus can float around as the release
    # dictates.
    #
    # @see extra_runtime_dependencies
    #
    # @note This is incompatible with +preload_app!+.
    # @note This is only supported for RubyGems 2.2+
    def prune_bundler(answer=true)
      @options[:prune_bundler] = answer
    end

    # By default, Puma will raise SignalException when SIGTERM is received. In
    # environments where SIGTERM is something expected, you can suppress these

Review comment (bug):
I'm not sure *exactly* why the tests are failing, but (for what it's worth) changing this method makes the tests pass:
```suggestion
    def on_booted(&block)
      @options[:on_booted] ||= []
      @options[:on_booted] << block
    end
```

Code after:

    # Code to run in the master after a worker has been started. The worker's
    # index is passed as an argument.
    #
    # This is called everytime a worker is to be started.
    #
    # @note Cluster mode only.
    # @example
    #   after_worker_fork do
    #     puts 'After worker fork...'
    #   end
    def after_worker_fork(&block)
      process_hook :after_worker_fork, nil, block, 'after_worker_fork'
    end

    alias_method :after_worker_boot, :after_worker_fork

    # Code to run after puma is booted (works for both: single and clustered)
    #
    # @example
    #   on_booted do
    #     puts 'After booting...'
    #   end
    def on_booted(&block)
      @config.options[:events].on_booted(&block)
    end

    # When `fork_worker` is enabled, code to run in Worker 0
    # before all other workers are re-forked from this process,
    # after the server has temporarily stopped serving requests
    # (once per complete refork cycle).
    #
    # This can be used to trigger extra garbage-collection to maximize
    # copy-on-write efficiency, or close any connections to remote servers
    # (database, Redis, ...) that were opened while the server was running.
    #
    # This can be called multiple times to add several hooks.
    #
    # @note Cluster mode with `fork_worker` enabled only.
    # @example
    #   on_refork do
    #     3.times {GC.start}
    #   end
    # @version 5.0.0
    #
    def on_refork(key = nil, &block)
      process_hook :before_refork, key, block, 'on_refork'
    end

    # Code to run out-of-band when the worker is idle.
    # These hooks run immediately after a request has finished