From 99f998da87211b9bb5b3fa2a47ee1b2160eb1322 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 3 Oct 2009 03:31:31 -0700 Subject: configurator: rainbows settings must be in a block This should make it easier to maintain/read configs that are Rainbows-specific --- lib/rainbows/configurator.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/rainbows/configurator.rb') diff --git a/lib/rainbows/configurator.rb b/lib/rainbows/configurator.rb index 2fb42fe..1d25f9e 100644 --- a/lib/rainbows/configurator.rb +++ b/lib/rainbows/configurator.rb @@ -3,7 +3,16 @@ module Rainbows class Configurator < ::Unicorn::Configurator + # configures rainbows + def rainbows(&block) + block_given? or raise ArgumentError, "rainbows requires a block" + instance_eval(&block) + end + + private + def use(model) + assert_in_rainbows begin model = Rainbows.const_get(model) rescue NameError @@ -16,11 +25,21 @@ module Rainbows end def worker_connections(nr) + assert_in_rainbows (Integer === nr && nr > 0) || nr.nil? or raise ArgumentError, "worker_connections must be an Integer or nil" set[:worker_connections] = nr end + private + + def assert_in_rainbows # :nodoc: + c = caller + c.grep(/`rainbows'\z/).empty? and + raise ArgumentError, + "#{%r!`(\w+)'\z!.match(c.first)[1]} must be called in `rainbows'" + end + end end -- cgit v1.2.3-24-ge0c7