From 54794fc823c40d79ab29f1d44d0158d65e218164 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Tue, 31 Mar 2009 09:52:49 -0700 Subject: [PATCH] Pass the class to configure blocks This allows for the following idiom in top-level apps: configure do |app| set :foo, app.root + '/foo' end --- lib/sinatra/base.rb | 2 +- test/base_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 6645e5eb..9afe8856 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -811,7 +811,7 @@ module Sinatra # Set configuration options for Sinatra and/or the app. # Allows scoping of settings for certain environments. def configure(*envs, &block) - yield if envs.empty? || envs.include?(environment.to_sym) + yield self if envs.empty? || envs.include?(environment.to_sym) end # Use the specified Rack middleware diff --git a/test/base_test.rb b/test/base_test.rb index 4d391f67..951e267c 100644 --- a/test/base_test.rb +++ b/test/base_test.rb @@ -37,6 +37,18 @@ class BaseTest < Test::Unit::TestCase assert_equal 'Foo: ', response.body end end + + it "passes the subclass to configure blocks" do + ref = nil + TestApp.configure { |app| ref = app } + assert_equal TestApp, ref + end + + it "allows the configure block arg to be omitted and does not change context" do + context = nil + TestApp.configure { context = self } + assert_equal self, context + end end describe "Sinatra::Base as Rack middleware" do