mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Add enable/disable methods to Application
These methods take multiple option name arguments and set their values to true (enable) or false (disable). Purely sugar.
This commit is contained in:
parent
a54d7cc321
commit
64a2dee4f0
2 changed files with 47 additions and 3 deletions
|
@ -867,9 +867,8 @@ module Sinatra
|
|||
# top-level the method is forwarded to the default application
|
||||
# (Sinatra::application).
|
||||
FORWARD_METHODS = %w[
|
||||
get put post delete head
|
||||
template layout before error not_found
|
||||
configures configure set_options set_option
|
||||
get put post delete head template layout before error not_found
|
||||
configures configure set_options set_option enable disable
|
||||
]
|
||||
|
||||
# Create a new Application with a default configuration taken
|
||||
|
@ -974,6 +973,19 @@ module Sinatra
|
|||
alias :set_option :set
|
||||
alias :set_options :set
|
||||
|
||||
# Enable the options specified by setting their values to true. For
|
||||
# example, to enable sessions and logging:
|
||||
# enable :sessions, :logging
|
||||
def enable(*opts)
|
||||
opts.each { |key| set(key, true) }
|
||||
end
|
||||
|
||||
# Disable the options specified by setting their values to false. For
|
||||
# example, to disable logging and automatic run:
|
||||
# disable :logging, :run
|
||||
def disable(*opts)
|
||||
opts.each { |key| set(key, false) }
|
||||
end
|
||||
|
||||
# Define an event handler for the given request method and path
|
||||
# spec. The block is executed when a request matches the method
|
||||
|
|
|
@ -252,4 +252,36 @@ context "Options in an app" do
|
|||
@app.options.bar.should.equal 'hello, world'
|
||||
end
|
||||
|
||||
specify "can be enabled on app" do
|
||||
@app.options.foo.should.be.nil
|
||||
@app.enable :sessions, :foo, :bar
|
||||
@app.options.sessions.should.equal true
|
||||
@app.options.foo.should.equal true
|
||||
@app.options.bar.should.equal true
|
||||
end
|
||||
|
||||
specify "can be enabled from top-level" do
|
||||
@app.options.foo.should.be.nil
|
||||
enable :sessions, :foo, :bar
|
||||
@app.options.sessions.should.equal true
|
||||
@app.options.foo.should.equal true
|
||||
@app.options.bar.should.equal true
|
||||
end
|
||||
|
||||
specify "can be disabled on app" do
|
||||
@app.options.foo.should.be.nil
|
||||
@app.disable :sessions, :foo, :bar
|
||||
@app.options.sessions.should.equal false
|
||||
@app.options.foo.should.equal false
|
||||
@app.options.bar.should.equal false
|
||||
end
|
||||
|
||||
specify "can be enabled from top-level" do
|
||||
@app.options.foo.should.be.nil
|
||||
disable :sessions, :foo, :bar
|
||||
@app.options.sessions.should.equal false
|
||||
@app.options.foo.should.equal false
|
||||
@app.options.bar.should.equal false
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue