rtomayko-sinatra 0.8.10 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +96 -0
- data/README.rdoc +87 -135
- data/Rakefile +1 -6
- data/compat/events_test.rb +7 -10
- data/compat/helper.rb +1 -13
- data/lib/sinatra.rb +0 -5
- data/lib/sinatra/base.rb +45 -108
- data/lib/sinatra/compat.rb +44 -142
- data/lib/sinatra/test.rb +90 -94
- data/lib/sinatra/test/rspec.rb +0 -7
- data/lib/sinatra/test/spec.rb +0 -7
- data/lib/sinatra/test/unit.rb +1 -1
- data/sinatra.gemspec +5 -8
- data/test/base_test.rb +14 -33
- data/test/builder_test.rb +16 -12
- data/test/erb_test.rb +16 -11
- data/test/filter_test.rb +12 -8
- data/test/haml_test.rb +18 -14
- data/test/helpers_test.rb +62 -55
- data/test/mapped_error_test.rb +24 -43
- data/test/middleware_test.rb +13 -8
- data/test/options_test.rb +35 -29
- data/test/reload_test.rb +20 -16
- data/test/request_test.rb +5 -12
- data/test/result_test.rb +20 -16
- data/test/routing_test.rb +64 -150
- data/test/sass_test.rb +12 -8
- data/test/sinatra_test.rb +4 -2
- data/test/static_test.rb +19 -16
- data/test/templates_test.rb +19 -23
- metadata +6 -8
- data/AUTHORS +0 -40
- data/CHANGES +0 -185
- data/lib/sinatra/test/bacon.rb +0 -17
- data/test/helper.rb +0 -25
data/Rakefile
CHANGED
@@ -152,12 +152,7 @@ def source_version
|
|
152
152
|
line.match(/.*VERSION = '(.*)'/)[1]
|
153
153
|
end
|
154
154
|
|
155
|
-
|
156
|
-
FileList[
|
157
|
-
'{lib,test,compat,images}/**',
|
158
|
-
'Rakefile', 'CHANGES', 'README.rdoc'
|
159
|
-
]
|
160
|
-
file 'sinatra.gemspec' => project_files do |f|
|
155
|
+
file 'sinatra.gemspec' => FileList['{lib,test,images}/**','Rakefile'] do |f|
|
161
156
|
# read spec file and split out manifest section
|
162
157
|
spec = File.read(f.name)
|
163
158
|
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
data/compat/events_test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
3
|
context "Simple Events" do
|
4
|
+
|
4
5
|
def simple_request_hash(method, path)
|
5
6
|
Rack::Request.new({
|
6
7
|
'REQUEST_METHOD' => method.to_s.upcase,
|
@@ -13,16 +14,16 @@ context "Simple Events" do
|
|
13
14
|
|
14
15
|
def invoke_simple(path, request_path, &b)
|
15
16
|
params = nil
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
mock_app {
|
18
|
+
get path do
|
19
|
+
params = self.params
|
20
|
+
b.call if b
|
21
|
+
end
|
22
|
+
}
|
20
23
|
get_it request_path
|
21
24
|
MockResult.new(b, params)
|
22
25
|
end
|
23
26
|
|
24
|
-
setup { Sinatra.application = nil }
|
25
|
-
|
26
27
|
specify "return last value" do
|
27
28
|
block = Proc.new { 'Simple' }
|
28
29
|
result = invoke_simple('/', '/', &block)
|
@@ -37,7 +38,6 @@ context "Simple Events" do
|
|
37
38
|
result.params.should.equal "foo" => 'a', "bar" => 'b'
|
38
39
|
|
39
40
|
# unscapes
|
40
|
-
Sinatra.application = nil
|
41
41
|
result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany')
|
42
42
|
result.should.not.be.nil
|
43
43
|
result.params.should.equal "foo" => 'a', "bar" => 'blake mizerany'
|
@@ -48,17 +48,14 @@ context "Simple Events" do
|
|
48
48
|
result.should.not.be.nil
|
49
49
|
result.params.should.equal "foo" => 'a', "bar" => 'b'
|
50
50
|
|
51
|
-
Sinatra.application = nil
|
52
51
|
result = invoke_simple('/?:foo?/?:bar?', '/a/')
|
53
52
|
result.should.not.be.nil
|
54
53
|
result.params.should.equal "foo" => 'a', "bar" => nil
|
55
54
|
|
56
|
-
Sinatra.application = nil
|
57
55
|
result = invoke_simple('/?:foo?/?:bar?', '/a')
|
58
56
|
result.should.not.be.nil
|
59
57
|
result.params.should.equal "foo" => 'a', "bar" => nil
|
60
58
|
|
61
|
-
Sinatra.application = nil
|
62
59
|
result = invoke_simple('/:foo?/?:bar?', '/')
|
63
60
|
result.should.not.be.nil
|
64
61
|
result.params.should.equal "foo" => nil, "bar" => nil
|
data/compat/helper.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'mocha'
|
3
3
|
|
4
|
-
# disable warnings in compat specs.
|
5
|
-
$VERBOSE = nil
|
6
|
-
|
7
4
|
$:.unshift File.dirname(File.dirname(__FILE__)) + "/lib"
|
8
5
|
|
9
6
|
ENV['RACK_ENV'] ||= 'test'
|
@@ -13,18 +10,9 @@ require 'sinatra/test'
|
|
13
10
|
require 'sinatra/test/unit'
|
14
11
|
require 'sinatra/test/spec'
|
15
12
|
|
16
|
-
module Sinatra::Test
|
17
|
-
# we need to remove the new test helper methods since they conflict with
|
18
|
-
# the top-level methods of the same name.
|
19
|
-
%w(get head post put delete).each do |verb|
|
20
|
-
remove_method verb
|
21
|
-
end
|
22
|
-
include Sinatra::Delegator
|
23
|
-
end
|
24
|
-
|
25
13
|
class Test::Unit::TestCase
|
26
|
-
include Sinatra::Test
|
27
14
|
def setup
|
28
15
|
@app = lambda { |env| Sinatra::Application.call(env) }
|
29
16
|
end
|
17
|
+
include Sinatra::Test
|
30
18
|
end
|
data/lib/sinatra.rb
CHANGED
data/lib/sinatra/base.rb
CHANGED
@@ -4,23 +4,12 @@ require 'rack'
|
|
4
4
|
require 'rack/builder'
|
5
5
|
|
6
6
|
module Sinatra
|
7
|
-
VERSION = '0.
|
7
|
+
VERSION = '0.9.0'
|
8
8
|
|
9
9
|
class Request < Rack::Request
|
10
10
|
def user_agent
|
11
11
|
@env['HTTP_USER_AGENT']
|
12
12
|
end
|
13
|
-
|
14
|
-
def accept
|
15
|
-
@env['HTTP_ACCEPT'].split(',').map { |a| a.strip }
|
16
|
-
end
|
17
|
-
|
18
|
-
# Override Rack 0.9.x's #params implementation (see #72 in lighthouse)
|
19
|
-
def params
|
20
|
-
self.GET.update(self.POST)
|
21
|
-
rescue EOFError => boom
|
22
|
-
self.GET
|
23
|
-
end
|
24
13
|
end
|
25
14
|
|
26
15
|
class Response < Rack::Response
|
@@ -77,7 +66,7 @@ module Sinatra
|
|
77
66
|
def redirect(uri, *args)
|
78
67
|
status 302
|
79
68
|
response['Location'] = uri
|
80
|
-
halt
|
69
|
+
halt *args
|
81
70
|
end
|
82
71
|
|
83
72
|
# Halt processing and return the error status provided.
|
@@ -99,7 +88,9 @@ module Sinatra
|
|
99
88
|
|
100
89
|
# Look up a media type by file extension in Rack's mime registry.
|
101
90
|
def media_type(type)
|
102
|
-
|
91
|
+
return type if type.nil? || type.to_s.include?('/')
|
92
|
+
type = ".#{type}" unless type.to_s[0] == ?.
|
93
|
+
Rack::Mime.mime_type(type, nil)
|
103
94
|
end
|
104
95
|
|
105
96
|
# Set the Content-Type of the response body given a media type or file
|
@@ -142,7 +133,7 @@ module Sinatra
|
|
142
133
|
class StaticFile < ::File #:nodoc:
|
143
134
|
alias_method :to_path, :path
|
144
135
|
def each
|
145
|
-
while buf = read(
|
136
|
+
while buf = read(8196)
|
146
137
|
yield buf
|
147
138
|
end
|
148
139
|
end
|
@@ -217,7 +208,6 @@ module Sinatra
|
|
217
208
|
|
218
209
|
def lookup_layout(engine, options)
|
219
210
|
return if options[:layout] == false
|
220
|
-
options.delete(:layout) if options[:layout] == true
|
221
211
|
template = options[:layout] || :layout
|
222
212
|
data = lookup_template(engine, template, options)
|
223
213
|
[template, data]
|
@@ -306,10 +296,10 @@ module Sinatra
|
|
306
296
|
attr_accessor :env, :request, :response, :params
|
307
297
|
|
308
298
|
def call!(env)
|
309
|
-
@env
|
310
|
-
@request
|
299
|
+
@env = env
|
300
|
+
@request = Request.new(env)
|
311
301
|
@response = Response.new
|
312
|
-
@params
|
302
|
+
@params = nil
|
313
303
|
error_detection { dispatch! }
|
314
304
|
@response.finish
|
315
305
|
end
|
@@ -331,9 +321,10 @@ module Sinatra
|
|
331
321
|
self.class.filters.each {|block| instance_eval(&block)}
|
332
322
|
if routes = self.class.routes[@request.request_method]
|
333
323
|
path = @request.path_info
|
334
|
-
original_params =
|
324
|
+
original_params = Hash.new{ |hash,k| hash[k.to_s] if Symbol === k }
|
325
|
+
original_params.merge! @request.params
|
335
326
|
|
336
|
-
routes.each do |pattern, keys, conditions,
|
327
|
+
routes.each do |pattern, keys, conditions, block|
|
337
328
|
if pattern =~ path
|
338
329
|
values = $~.captures.map{|val| val && unescape(val) }
|
339
330
|
params =
|
@@ -351,12 +342,13 @@ module Sinatra
|
|
351
342
|
else
|
352
343
|
{}
|
353
344
|
end
|
354
|
-
@params = original_params.
|
345
|
+
@params = original_params.dup
|
346
|
+
@params.merge!(params)
|
355
347
|
|
356
348
|
catch(:pass) {
|
357
349
|
conditions.each { |cond|
|
358
350
|
throw :pass if instance_eval(&cond) == false }
|
359
|
-
return invoke(
|
351
|
+
return invoke(block)
|
360
352
|
}
|
361
353
|
end
|
362
354
|
end
|
@@ -364,22 +356,6 @@ module Sinatra
|
|
364
356
|
raise NotFound
|
365
357
|
end
|
366
358
|
|
367
|
-
def nested_params(params)
|
368
|
-
return indifferent_hash.merge(params) if !params.keys.join.include?('[')
|
369
|
-
params.inject indifferent_hash do |res, (key,val)|
|
370
|
-
if key =~ /\[.*\]/
|
371
|
-
splat = key.scan(/(^[^\[]+)|\[([^\]]+)\]/).flatten.compact
|
372
|
-
head, last = splat[0..-2], splat[-1]
|
373
|
-
head.inject(res){ |s,v| s[v] ||= indifferent_hash }[last] = val
|
374
|
-
end
|
375
|
-
res
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
def indifferent_hash
|
380
|
-
Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
|
381
|
-
end
|
382
|
-
|
383
359
|
def invoke(block)
|
384
360
|
res = catch(:halt) { instance_eval(&block) }
|
385
361
|
case
|
@@ -401,12 +377,16 @@ module Sinatra
|
|
401
377
|
else
|
402
378
|
@response.body = res
|
403
379
|
end
|
380
|
+
when res.kind_of?(Symbol) # TODO: deprecate this.
|
381
|
+
@response.body = __send__(res)
|
404
382
|
when res.respond_to?(:each)
|
405
383
|
@response.body = res
|
406
384
|
when (100...599) === res
|
407
385
|
@response.status = res
|
408
386
|
when res.nil?
|
409
387
|
@response.body = []
|
388
|
+
else
|
389
|
+
raise TypeError, "#{res.inspect} not supported"
|
410
390
|
end
|
411
391
|
res
|
412
392
|
end
|
@@ -422,12 +402,6 @@ module Sinatra
|
|
422
402
|
invoke handler unless handler.nil?
|
423
403
|
rescue ::Exception => boom
|
424
404
|
@env['sinatra.error'] = boom
|
425
|
-
|
426
|
-
if options.dump_errors?
|
427
|
-
msg = ["#{boom.class} - #{boom.message}:", *boom.backtrace].join("\n ")
|
428
|
-
@env['rack.errors'] << msg
|
429
|
-
end
|
430
|
-
|
431
405
|
raise boom if options.raise_errors?
|
432
406
|
@response.status = 500
|
433
407
|
invoke errmap[boom.class] || errmap[Exception]
|
@@ -480,10 +454,6 @@ module Sinatra
|
|
480
454
|
end
|
481
455
|
end
|
482
456
|
|
483
|
-
def not_found(&block)
|
484
|
-
error 404, &block
|
485
|
-
end
|
486
|
-
|
487
457
|
def template(name, &block)
|
488
458
|
templates[name] = block
|
489
459
|
end
|
@@ -493,16 +463,11 @@ module Sinatra
|
|
493
463
|
end
|
494
464
|
|
495
465
|
def use_in_file_templates!
|
496
|
-
line = caller.detect
|
497
|
-
|
498
|
-
/lib\/sinatra.*\.rb/,
|
499
|
-
/\(.*\)/,
|
500
|
-
/rubygems\/custom_require\.rb/
|
501
|
-
].all? { |x| s !~ x }
|
502
|
-
end
|
466
|
+
line = caller.detect { |s| s !~ /lib\/sinatra.*\.rb/ &&
|
467
|
+
s !~ /\(.*\)/ }
|
503
468
|
file = line.sub(/:\d+.*$/, '')
|
504
469
|
if data = ::IO.read(file).split('__END__')[1]
|
505
|
-
data.gsub!
|
470
|
+
data.gsub! /\r\n/, "\n"
|
506
471
|
template = nil
|
507
472
|
data.each_line do |line|
|
508
473
|
if line =~ /^@@\s*(.*)/
|
@@ -514,13 +479,6 @@ module Sinatra
|
|
514
479
|
end
|
515
480
|
end
|
516
481
|
|
517
|
-
# Look up a media type by file extension in Rack's mime registry.
|
518
|
-
def media_type(type)
|
519
|
-
return type if type.nil? || type.to_s.include?('/')
|
520
|
-
type = ".#{type}" unless type.to_s[0] == ?.
|
521
|
-
Rack::Mime.mime_type(type, nil)
|
522
|
-
end
|
523
|
-
|
524
482
|
def before(&block)
|
525
483
|
@filters << block
|
526
484
|
end
|
@@ -544,24 +502,9 @@ module Sinatra
|
|
544
502
|
}
|
545
503
|
end
|
546
504
|
|
547
|
-
def accept_mime_types(types)
|
548
|
-
types = [types] unless types.kind_of? Array
|
549
|
-
types.map!{|t| media_type(t)}
|
550
|
-
|
551
|
-
condition {
|
552
|
-
matching_types = (request.accept & types)
|
553
|
-
unless matching_types.empty?
|
554
|
-
response.headers['Content-Type'] = matching_types.first
|
555
|
-
true
|
556
|
-
else
|
557
|
-
false
|
558
|
-
end
|
559
|
-
}
|
560
|
-
end
|
561
|
-
|
562
505
|
def get(path, opts={}, &block)
|
563
506
|
conditions = @conditions.dup
|
564
|
-
route
|
507
|
+
route 'GET', path, opts, &block
|
565
508
|
|
566
509
|
@conditions = conditions
|
567
510
|
head(path, opts) { invoke(block) ; [] }
|
@@ -573,20 +516,14 @@ module Sinatra
|
|
573
516
|
def head(path, opts={}, &bk); route 'HEAD', path, opts, &bk; end
|
574
517
|
|
575
518
|
private
|
576
|
-
def route(
|
519
|
+
def route(method, path, opts={}, &block)
|
577
520
|
host_name opts[:host] if opts.key?(:host)
|
578
521
|
user_agent opts[:agent] if opts.key?(:agent)
|
579
|
-
accept_mime_types opts[:provides] if opts.key?(:provides)
|
580
522
|
|
581
523
|
pattern, keys = compile(path)
|
582
524
|
conditions, @conditions = @conditions, []
|
583
|
-
|
584
|
-
|
585
|
-
unbound_method = instance_method("#{verb} #{path}")
|
586
|
-
block = lambda { unbound_method.bind(self).call }
|
587
|
-
|
588
|
-
(routes[verb] ||= []).
|
589
|
-
push([pattern, keys, conditions, block]).last
|
525
|
+
(routes[method] ||= []).
|
526
|
+
push [pattern, keys, conditions, block]
|
590
527
|
end
|
591
528
|
|
592
529
|
def compile(path)
|
@@ -685,7 +622,6 @@ module Sinatra
|
|
685
622
|
end
|
686
623
|
|
687
624
|
set :raise_errors, true
|
688
|
-
set :dump_errors, false
|
689
625
|
set :sessions, false
|
690
626
|
set :logging, false
|
691
627
|
set :methodoverride, false
|
@@ -779,7 +715,6 @@ module Sinatra
|
|
779
715
|
|
780
716
|
class Default < Base
|
781
717
|
set :raise_errors, false
|
782
|
-
set :dump_errors, true
|
783
718
|
set :sessions, false
|
784
719
|
set :logging, true
|
785
720
|
set :methodoverride, true
|
@@ -787,27 +722,29 @@ module Sinatra
|
|
787
722
|
set :run, false
|
788
723
|
set :reload, Proc.new { app_file? && development? }
|
789
724
|
|
790
|
-
|
791
|
-
@reloading ||= false
|
792
|
-
end
|
725
|
+
@reloading = false
|
793
726
|
|
794
|
-
|
795
|
-
|
796
|
-
|
727
|
+
class << self
|
728
|
+
def reloading?
|
729
|
+
@reloading
|
730
|
+
end
|
797
731
|
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
end
|
732
|
+
def configure(*envs)
|
733
|
+
super unless reloading?
|
734
|
+
end
|
802
735
|
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
::Kernel.load app_file
|
808
|
-
@reloading = false
|
809
|
-
end
|
736
|
+
def call(env)
|
737
|
+
reload! if reload?
|
738
|
+
super
|
739
|
+
end
|
810
740
|
|
741
|
+
def reload!
|
742
|
+
@reloading = true
|
743
|
+
superclass.send :inherited, self
|
744
|
+
::Kernel.load app_file
|
745
|
+
@reloading = false
|
746
|
+
end
|
747
|
+
end
|
811
748
|
end
|
812
749
|
|
813
750
|
class Application < Default
|
data/lib/sinatra/compat.rb
CHANGED
@@ -1,102 +1,58 @@
|
|
1
|
-
# Sinatra 0.3.x compatibility module.
|
2
|
-
#
|
3
|
-
# The following code makes Sinatra 0.9.x compatible with Sinatra 0.3.x to
|
4
|
-
# ease the transition to the final 1.0 release. Everything defined in this
|
5
|
-
# file will be removed for the 1.0 release.
|
6
|
-
|
7
1
|
require 'ostruct'
|
8
2
|
require 'sinatra/base'
|
9
3
|
require 'sinatra/main'
|
10
4
|
|
11
|
-
#
|
12
|
-
def sinatra_warn(*message)
|
13
|
-
line = caller.
|
14
|
-
detect { |line| line !~ /(?:lib\/sinatra\/|__DELEGATE__)/ }.
|
15
|
-
sub(/:in .*/, '')
|
16
|
-
warn "#{line}: warning: #{message.join(' ')}"
|
17
|
-
end
|
18
|
-
|
19
|
-
# Rack now supports evented and swiftiplied mongrels through separate
|
20
|
-
# handler.
|
5
|
+
# Deprecated. Do we still need this?
|
21
6
|
if ENV['SWIFT']
|
22
|
-
sinatra_warn 'the SWIFT environment variable is deprecated;',
|
23
|
-
'use Rack::Handler::SwiftipliedMongrel instead.'
|
24
7
|
require 'swiftcore/swiftiplied_mongrel'
|
25
8
|
puts "Using Swiftiplied Mongrel"
|
26
9
|
elsif ENV['EVENT']
|
27
|
-
sinatra_warn 'the EVENT environment variable is deprecated;',
|
28
|
-
'use Rack::Handler::EventedMongrel instead.'
|
29
10
|
require 'swiftcore/evented_mongrel'
|
30
11
|
puts "Using Evented Mongrel"
|
31
12
|
end
|
32
13
|
|
33
|
-
# Make Rack 0.9.0 backward compatibile with 0.4.0
|
34
|
-
#
|
35
|
-
# MIME_TYPES constants due to Sinatra example code.
|
14
|
+
# Deprecated. Make Rack 0.9.0 backward compatibile with 0.4.0
|
15
|
+
# mime types
|
36
16
|
require 'rack/file'
|
37
17
|
class Rack::File
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
const_set :MIME_TYPES, hash
|
42
|
-
sinatra_warn 'Rack::File::MIME_TYPES is deprecated; use Rack::Mime instead.'
|
43
|
-
hash
|
44
|
-
else
|
45
|
-
super
|
46
|
-
end
|
18
|
+
unless defined? MIME_TYPES
|
19
|
+
MIME_TYPES = Hash.new {|hash,key|
|
20
|
+
Rack::Mime::MIME_TYPES[".#{key}"] }
|
47
21
|
end
|
48
22
|
end
|
49
23
|
|
24
|
+
# Deprecated. Rack::Utils will not extend itself in the future. Sinatra::Base
|
25
|
+
# includes Rack::Utils, however.
|
26
|
+
module Rack::Utils ; extend self ; end
|
27
|
+
|
50
28
|
module Sinatra
|
51
29
|
module Compat
|
52
30
|
end
|
53
31
|
|
54
|
-
#
|
55
|
-
# internal server error.
|
32
|
+
# Deprecated. Use: error
|
56
33
|
class ServerError < RuntimeError
|
57
|
-
def initialize(*args, &block)
|
58
|
-
sinatra_warn 'Sinatra::ServerError is deprecated;',
|
59
|
-
'use another exception, error, or Kernel#fail instead.'
|
60
|
-
end
|
61
34
|
def code ; 500 ; end
|
62
35
|
end
|
63
36
|
|
64
37
|
class Default < Base
|
65
|
-
|
66
|
-
|
67
|
-
sinatra_warn 'Sinatra::Application::FORWARD_METHODS is deprecated;',
|
68
|
-
'use Sinatra::Delegator::METHODS instead.'
|
69
|
-
const_set :FORWARD_METHODS, Sinatra::Delegator::METHODS
|
70
|
-
Sinatra::Delegator::METHODS
|
71
|
-
else
|
72
|
-
super
|
73
|
-
end
|
74
|
-
end
|
38
|
+
# Deprecated.
|
39
|
+
FORWARD_METHODS = Sinatra::Delegator::METHODS
|
75
40
|
|
76
41
|
# Deprecated. Use: response['Header-Name']
|
77
42
|
def headers(header=nil)
|
78
|
-
sinatra_warn "The 'headers' method is deprecated; use 'response' instead."
|
79
43
|
response.headers.merge!(header) if header
|
80
44
|
response.headers
|
81
45
|
end
|
82
46
|
alias :header :headers
|
83
47
|
|
84
48
|
# Deprecated. Use: halt
|
85
|
-
|
86
|
-
sinatra_warn "The 'stop' method is deprecated; use 'halt' instead."
|
87
|
-
halt(*args, &block)
|
88
|
-
end
|
49
|
+
alias :stop :halt
|
89
50
|
|
90
51
|
# Deprecated. Use: etag
|
91
|
-
|
92
|
-
sinatra_warn "The 'entity_tag' method is deprecated; use 'etag' instead."
|
93
|
-
etag(*args, &block)
|
94
|
-
end
|
52
|
+
alias :entity_tag :etag
|
95
53
|
|
96
54
|
# The :disposition option is deprecated; use: #attachment. This method
|
97
55
|
# setting the Content-Transfer-Encoding header is deprecated.
|
98
|
-
#--
|
99
|
-
# TODO deprecation warning for :disposition argument.
|
100
56
|
def send_file(path, opts={})
|
101
57
|
opts[:disposition] = 'attachment' if !opts.key?(:disposition)
|
102
58
|
attachment opts[:filename] || path if opts[:filename] || opts[:disposition]
|
@@ -104,89 +60,48 @@ module Sinatra
|
|
104
60
|
super(path, opts)
|
105
61
|
end
|
106
62
|
|
107
|
-
|
108
|
-
# deprecated. Override the invoke method to detect those types of return
|
109
|
-
# values.
|
110
|
-
def invoke(handler)
|
111
|
-
res = super
|
112
|
-
case
|
113
|
-
when res.kind_of?(Symbol)
|
114
|
-
sinatra_warn "Invoking the :#{res} helper by returning a Symbol is deprecated;",
|
115
|
-
"call the helper directly instead."
|
116
|
-
@response.body = __send__(res)
|
117
|
-
when res.respond_to?(:to_result)
|
118
|
-
sinatra_warn "The to_result convention is deprecated."
|
119
|
-
@response.body = res.to_result(self)
|
120
|
-
end
|
121
|
-
res
|
122
|
-
end
|
123
|
-
|
124
|
-
def options
|
125
|
-
Options.new(self.class)
|
126
|
-
end
|
127
|
-
|
128
|
-
class Options < Struct.new(:target) #:nodoc:
|
129
|
-
def method_missing(name, *args, &block)
|
130
|
-
if target.respond_to?(name)
|
131
|
-
target.__send__(name, *args, &block)
|
132
|
-
elsif args.empty? && name.to_s !~ /=$/
|
133
|
-
sinatra_warn 'accessing undefined options will raise a NameError in Sinatra 1.0'
|
134
|
-
nil
|
135
|
-
else
|
136
|
-
super
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
63
|
+
def options ; self.class.options ; end
|
140
64
|
|
141
65
|
class << self
|
142
66
|
# Deprecated. Options are stored directly on the class object.
|
143
|
-
def options
|
144
|
-
|
145
|
-
|
67
|
+
def options ; Options.new(self) ; end
|
68
|
+
|
69
|
+
class Options < Struct.new(:target) #:nodoc:
|
70
|
+
def method_missing(name, *args, &block)
|
71
|
+
if target.respond_to?(name)
|
72
|
+
target.__send__(name, *args, &block)
|
73
|
+
elsif args.empty? && name.to_s !~ /=$/
|
74
|
+
nil
|
75
|
+
else
|
76
|
+
super
|
77
|
+
end
|
78
|
+
end
|
146
79
|
end
|
147
80
|
|
148
81
|
# Deprecated. Use: configure
|
149
|
-
|
150
|
-
sinatra_warn "The 'configures' method is deprecated; use 'configure' instead."
|
151
|
-
configure(*args, &block)
|
152
|
-
end
|
82
|
+
alias :configures :configure
|
153
83
|
|
154
84
|
# Deprecated. Use: set
|
155
85
|
def default_options
|
156
|
-
sinatra_warn "Sinatra::Application.default_options is deprecated; use 'set' instead."
|
157
86
|
fake = lambda { |options| set(options) }
|
158
87
|
def fake.merge!(options) ; call(options) ; end
|
159
88
|
fake
|
160
89
|
end
|
161
90
|
|
162
91
|
# Deprecated. Use: set
|
163
|
-
|
164
|
-
|
165
|
-
set(*args, &block)
|
166
|
-
end
|
167
|
-
|
168
|
-
def set_options(*args, &block)
|
169
|
-
sinatra_warn "The 'set_options' method is deprecated; use 'set' instead."
|
170
|
-
set(*args, &block)
|
171
|
-
end
|
92
|
+
alias :set_option :set
|
93
|
+
alias :set_options :set
|
172
94
|
|
173
95
|
# Deprecated. Use: set :environment, ENV
|
174
96
|
def env=(value)
|
175
|
-
sinatra_warn "The :env option is deprecated; use :environment instead."
|
176
97
|
set :environment, value
|
177
98
|
end
|
178
|
-
|
179
|
-
# Deprecated. Use: options.environment
|
180
|
-
def env
|
181
|
-
sinatra_warn "The :env option is deprecated; use :environment instead."
|
182
|
-
environment
|
183
|
-
end
|
99
|
+
alias :env :environment
|
184
100
|
end
|
185
101
|
|
186
102
|
# Deprecated. Missing messages are no longer delegated to @response.
|
187
103
|
def method_missing(name, *args, &b)
|
188
104
|
if @response.respond_to?(name)
|
189
|
-
sinatra_warn "The '#{name}' method is deprecated; use 'response.#{name}' instead."
|
190
105
|
@response.send(name, *args, &b)
|
191
106
|
else
|
192
107
|
super
|
@@ -197,43 +112,30 @@ module Sinatra
|
|
197
112
|
class << self
|
198
113
|
# Deprecated. Use: Sinatra::Application
|
199
114
|
def application
|
200
|
-
sinatra_warn "Sinatra.application is deprecated; use Sinatra::Application instead."
|
201
115
|
Sinatra::Application
|
202
116
|
end
|
203
117
|
|
118
|
+
# Deprecated. Use: error 404
|
119
|
+
def not_found(&block)
|
120
|
+
error 404, &block
|
121
|
+
end
|
122
|
+
|
204
123
|
# Deprecated. Use: Sinatra::Application.reset!
|
205
124
|
def application=(value)
|
206
125
|
raise ArgumentError unless value.nil?
|
207
|
-
sinatra_warn "Setting Sinatra.application to nil is deprecated; create a new instance instead."
|
208
126
|
Sinatra.class_eval do
|
209
127
|
remove_const :Application
|
210
128
|
const_set :Application, Class.new(Sinatra::Default)
|
211
129
|
end
|
212
130
|
end
|
213
131
|
|
214
|
-
|
215
|
-
|
216
|
-
Sinatra::Application
|
217
|
-
end
|
218
|
-
|
219
|
-
def options
|
220
|
-
sinatra_warn "Sinatra.options is deprecated; use Sinatra::Application.option_name instead."
|
221
|
-
Sinatra::Application.options
|
222
|
-
end
|
223
|
-
|
224
|
-
def port
|
225
|
-
sinatra_warn "Sinatra.port is deprecated; use Sinatra::Application.port instead."
|
226
|
-
options.port
|
227
|
-
end
|
228
|
-
|
229
|
-
def host
|
230
|
-
sinatra_warn "Sinatra.host is deprecated; use Sinatra::Application.host instead."
|
231
|
-
options.host
|
232
|
-
end
|
132
|
+
# Deprecated. Use: Sinatra::Application
|
133
|
+
alias :build_application :application
|
233
134
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
end
|
135
|
+
# Deprecated.
|
136
|
+
def options ; Sinatra::Application.options ; end
|
137
|
+
def port ; options.port ; end
|
138
|
+
def host ; options.host ; end
|
139
|
+
def env ; options.environment ; end
|
238
140
|
end
|
239
141
|
end
|