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
This commit is contained in:
TJ Holowaychuk 2009-03-31 09:52:49 -07:00 committed by Ryan Tomayko
parent da8271f05b
commit 54794fc823
2 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -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