From b5a0a2cce2c10ade80c1bc9a54d73194bb520776 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 4 Oct 2009 20:52:36 -0700 Subject: limit Rainbows! configuration method exposure Only inject this method into Unicorn::Configurator to avoid polluting the namespace. --- lib/rainbows.rb | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/rainbows.rb b/lib/rainbows.rb index 04be9b4..4ba4b97 100644 --- a/lib/rainbows.rb +++ b/lib/rainbows.rb @@ -1,11 +1,6 @@ # -*- encoding: binary -*- require 'unicorn' -def Rainbows!(&block) - block_given? or raise ArgumentError, "Rainbows! requires a block" - Rainbows::HttpServer.setup(block) -end - module Rainbows require 'rainbows/const' @@ -14,11 +9,31 @@ module Rainbows require 'rainbows/base' class << self + + # runs the Rainbows! HttpServer with +app+ and +options+ and does + # not return until the server has exited. def run(app, options = {}) HttpServer.new(app, options).start.join end end + # configures Rainbows! with a given concurrency model to +use+ and + # a +worker_connections+ upper-bound. This method may be called + # inside a Unicorn/Rainbows configuration file: + # + # Rainbows! do + # use :Revactor # this may also be :ThreadSpawn or :ThreadPool + # worker_connections 128 + # end + # + # See the documentation for the respective Revactor, ThreadSpawn, + # and ThreadPool classes for descriptions and recommendations for + # each of them. + def Rainbows!(&block) + block_given? or raise ArgumentError, "Rainbows! requires a block" + HttpServer.setup(block) + end + # maps models to default worker counts, default worker count numbers are # pretty arbitrary and tuning them to your application and hardware is # highly recommended @@ -33,3 +48,6 @@ module Rainbows end end + +# inject the Rainbows! method into Unicorn::Configurator +Unicorn::Configurator.class_eval { include Rainbows } -- cgit v1.2.3-24-ge0c7