public
Fork of bmizerany/sinatra
Description: Classy web-development dressed in a DSL
Homepage: http://sinatrarb.com
Clone URL: git://github.com/JackDanger/sinatra.git
Move set_option(s) to Application, export to (main)

Move top-level set_option/set_options to Sinatra::Application#set
and plumb in delegates from (main).

NOTE: options set via these methods are no longer set in the
default_options Hash but directly on the current application's
options object.
rtomayko (author)
Tue Apr 15 01:25:09 -0700 2008
commit  fd0150da29d097fe1b4efc9f398c60caa4b380b2
tree    dde4d5a11a9e2b4f148a6008251a595acdbc4202
parent  2413987830ca004ba2da9be48b199cb82a654146
...
873
874
875
876
 
877
878
879
...
960
961
962
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
963
964
965
...
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
...
873
874
875
 
876
877
878
879
...
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
...
1321
1322
1323
 
 
 
 
 
 
 
 
1324
1325
1326
0
@@ -873,7 +873,7 @@ module Sinatra
0
     FORWARD_METHODS = %w[
0
       get put post delete head
0
       template layout before error not_found
0
- configures configure
0
+ configures configure set_options set_option
0
     ]
0
 
0
     # Create a new Application with a default configuration taken
0
@@ -960,6 +960,31 @@ module Sinatra
0
 
0
     alias :configure :configures
0
 
0
+ # When both +option+ and +value+ arguments are provided, set the option
0
+ # specified. With a single Hash argument, set all options specified in
0
+ # Hash. Options are available via the Application#options object.
0
+ #
0
+ # Setting individual options:
0
+ # set :port, 80
0
+ # set :env, :production
0
+ # set :views, '/path/to/views'
0
+ #
0
+ # Setting multiple options:
0
+ # set :port => 80,
0
+ # :env => :production,
0
+ # :views => '/path/to/views'
0
+ #
0
+ def set(option, value=self)
0
+ if value == self && option.kind_of?(Hash)
0
+ option.each { |key,val| set(key, val) }
0
+ else
0
+ options.send("#{option}=", value)
0
+ end
0
+ end
0
+
0
+ alias :set_option :set
0
+ alias :set_options :set
0
+
0
 
0
     # Define an event handler for the given request method and path
0
     # spec. The block is executed when a request matches the method
0
@@ -1296,14 +1321,6 @@ def use_in_file_templates!
0
   end
0
 end
0
 
0
-def set_options(opts)
0
- Sinatra::Application.default_options.merge!(opts)
0
-end
0
-
0
-def set_option(key, value)
0
- set_options(key => value)
0
-end
0
-
0
 def mime(ext, type)
0
   Rack::File::MIME_TYPES[ext.to_s] = type
0
 end
...
204
205
206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
0
@@ -204,3 +204,37 @@ context "Events in an app" do
0
 end
0
 
0
 
0
+context "Options in an app" do
0
+
0
+ setup do
0
+ Sinatra.application = nil
0
+ @app = Sinatra::application
0
+ end
0
+
0
+ specify "can be set singly on app" do
0
+ @app.set :foo, 1234
0
+ @app.options.foo.should.equal 1234
0
+ end
0
+
0
+ specify "can be set singly from top-level" do
0
+ set_option :foo, 1234
0
+ @app.options.foo.should.equal 1234
0
+ end
0
+
0
+ specify "can be set multiply on app" do
0
+ @app.options.foo.should.be.nil
0
+ @app.set :foo => 1234,
0
+ :bar => 'hello, world'
0
+ @app.options.foo.should.equal 1234
0
+ @app.options.bar.should.equal 'hello, world'
0
+ end
0
+
0
+ specify "can be set multiply from top-level" do
0
+ @app.options.foo.should.be.nil
0
+ set_options :foo => 1234,
0
+ :bar => 'hello, world'
0
+ @app.options.foo.should.equal 1234
0
+ @app.options.bar.should.equal 'hello, world'
0
+ end
0
+
0
+end
...
1
2
3
4
5
6
7
 
 
 
8
9
10
...
18
19
20
21
 
22
23
24
 
25
26
27
...
1
2
3
 
 
 
4
5
6
7
8
9
10
...
18
19
20
 
21
22
 
 
23
24
25
26
0
@@ -1,10 +1,10 @@
0
 require File.dirname(__FILE__) + '/helper'
0
 
0
 context "Sessions" do
0
-
0
- specify "should be off by default" do
0
- Sinatra.application = nil
0
 
0
+ setup { Sinatra.application = nil }
0
+
0
+ specify "should be off by default" do
0
     get '/asdf' do
0
       session[:test] = true
0
       "asdf"
0
@@ -18,10 +18,9 @@ context "Sessions" do
0
     assert ok?
0
     assert !include?('Set-Cookie')
0
   end
0
-
0
+
0
   specify "should be able to store data accross requests" do
0
- set_options(:sessions => true)
0
- Sinatra.application = nil
0
+ set_option :sessions, true
0
 
0
     get '/foo' do
0
       session[:test] = true

Comments

    No one has commented yet.