Permalink
Browse files

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
  • Loading branch information...
tj authored and rtomayko committed Mar 31, 2009
1 parent da8271f commit 54794fc823c40d79ab29f1d44d0158d65e218164
Showing with 13 additions and 1 deletion.
  1. +1 −1 lib/sinatra/base.rb
  2. +12 −0 test/base_test.rb
View
@@ -811,7 +811,7 @@ def test?; environment == :test end
# 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
View
@@ -37,6 +37,18 @@ class TestApp < Sinatra::Base
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

0 comments on commit 54794fc

Please sign in to comment.