sinatra 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sinatra might be problematic. Click here for more details.
- data/CHANGELOG +1 -0
- data/RakeFile +1 -2
- data/Rakefile +1 -2
- data/lib/sinatra/dsl.rb +23 -0
- data/lib/sinatra/event.rb +63 -10
- data/lib/sinatra/irb.rb +1 -0
- data/lib/sinatra/options.rb +6 -0
- data/lib/sinatra/server.rb +3 -0
- data/sinatra.gemspec +4 -5
- data/site/index.htm +7 -3
- data/site/index.html +7 -3
- data/test/sinatra/event_test.rb +9 -0
- metadata +3 -3
data/CHANGELOG
CHANGED
data/RakeFile
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rake/testtask'
|
2
2
|
require 'ftools'
|
3
|
-
require 'hoe'
|
4
3
|
|
5
4
|
Version = '0.1.0'
|
6
5
|
|
@@ -20,7 +19,7 @@ begin
|
|
20
19
|
p.email = "blake.mizerany@gmail.com"
|
21
20
|
p.test_pattern = 'test/**/*_test.rb'
|
22
21
|
p.include_rakefile = true
|
23
|
-
p.rdoc_pattern = ['README', 'LICENSE']
|
22
|
+
p.rdoc_pattern = ['README', 'LICENSE'] + Dir.glob('lib/**/*.rb') + Dir.glob('vendor/**/*.rb')
|
24
23
|
p.docs_host = "bmizerany@rubyforge.org:/var/www/gforge-projects/sinatra/"
|
25
24
|
end
|
26
25
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rake/testtask'
|
2
2
|
require 'ftools'
|
3
|
-
require 'hoe'
|
4
3
|
|
5
4
|
Version = '0.1.0'
|
6
5
|
|
@@ -20,7 +19,7 @@ begin
|
|
20
19
|
p.email = "blake.mizerany@gmail.com"
|
21
20
|
p.test_pattern = 'test/**/*_test.rb'
|
22
21
|
p.include_rakefile = true
|
23
|
-
p.rdoc_pattern = ['README', 'LICENSE']
|
22
|
+
p.rdoc_pattern = ['README', 'LICENSE'] + Dir.glob('lib/**/*.rb') + Dir.glob('vendor/**/*.rb')
|
24
23
|
p.docs_host = "bmizerany@rubyforge.org:/var/www/gforge-projects/sinatra/"
|
25
24
|
end
|
26
25
|
|
data/lib/sinatra/dsl.rb
CHANGED
@@ -54,11 +54,34 @@ module Sinatra
|
|
54
54
|
Sinatra::Event.new(:delete, path, &block)
|
55
55
|
end
|
56
56
|
|
57
|
+
# Run given block after each Event's execution
|
58
|
+
# Usage:
|
59
|
+
# before_attend do
|
60
|
+
# logger.debug "After event attend!"
|
61
|
+
# end
|
62
|
+
# or
|
63
|
+
# before_attend :authorize # authorize is a helper method defined using helpers
|
64
|
+
#
|
65
|
+
# Stop execution using - throw :halt
|
66
|
+
# before_attend do
|
67
|
+
# throw :halt, 401 unless has_access?
|
68
|
+
# end
|
69
|
+
# Throw a Symbol to execute a helper method
|
70
|
+
# Throw a String to render it as the content
|
71
|
+
# Throw a Fixnum to set the status
|
72
|
+
#
|
73
|
+
def before_attend(filter_name = nil, &block)
|
74
|
+
Sinatra::Event.before_attend(filter_name, &block)
|
75
|
+
end
|
76
|
+
|
57
77
|
# Run given block after each Event's execution
|
58
78
|
# Example:
|
59
79
|
# after_attend do
|
60
80
|
# logger.debug "After event attend!"
|
61
81
|
# end
|
82
|
+
# or
|
83
|
+
# after_attend :clean_up # clean_up is a helper method defined using helpers
|
84
|
+
#
|
62
85
|
def after_attend(filter_name = nil, &block)
|
63
86
|
Sinatra::Event.after_attend(filter_name, &block)
|
64
87
|
end
|
data/lib/sinatra/event.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
1
3
|
module Sinatra
|
2
4
|
|
3
5
|
module EventManager # :nodoc:
|
@@ -43,13 +45,30 @@ module Sinatra
|
|
43
45
|
|
44
46
|
cattr_accessor :logger
|
45
47
|
cattr_accessor :after_filters
|
48
|
+
cattr_accessor :before_filters
|
49
|
+
|
50
|
+
@@mutex = Mutex.new
|
46
51
|
|
52
|
+
self.before_filters = []
|
47
53
|
self.after_filters = []
|
48
54
|
|
49
|
-
def self.
|
50
|
-
|
55
|
+
def self.before_attend(method_name = nil, &block)
|
56
|
+
setup_filter(:before_filters, method_name, &block)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.after_attend(method_name = nil, &block)
|
60
|
+
setup_filter(:after_filters, method_name, &block)
|
51
61
|
end
|
52
62
|
|
63
|
+
def self.setup_filter(filter_set_name, method_name, &block)
|
64
|
+
raise "Must specify method or block" if method_name.nil? and !block_given?
|
65
|
+
send(filter_set_name) << if block_given?
|
66
|
+
block
|
67
|
+
else
|
68
|
+
method_name
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
53
72
|
after_attend :log_event
|
54
73
|
|
55
74
|
attr_reader :path, :verb
|
@@ -65,13 +84,27 @@ module Sinatra
|
|
65
84
|
def attend(request)
|
66
85
|
request.params.merge!(@route.params)
|
67
86
|
context = EventContext.new(request)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
87
|
+
run_safely do
|
88
|
+
caught = catch(:halt) do
|
89
|
+
call_filters(before_filters, context)
|
90
|
+
end
|
91
|
+
body = case caught
|
92
|
+
when :filter_chain_completed
|
93
|
+
begin
|
94
|
+
context.instance_eval(&@block) if @block
|
95
|
+
rescue => e
|
96
|
+
context.error e
|
97
|
+
end
|
98
|
+
when Symbol
|
99
|
+
context.send(caught)
|
100
|
+
when String
|
101
|
+
caught
|
102
|
+
when Fixnum
|
103
|
+
context.status caught
|
104
|
+
end
|
105
|
+
context.body context.body || body || ''
|
106
|
+
call_filters(after_filters, context)
|
73
107
|
end
|
74
|
-
run_through_after_filters(context)
|
75
108
|
context
|
76
109
|
end
|
77
110
|
alias :call :attend
|
@@ -82,8 +115,28 @@ module Sinatra
|
|
82
115
|
|
83
116
|
private
|
84
117
|
|
85
|
-
def
|
86
|
-
|
118
|
+
def run_safely
|
119
|
+
if Options.use_mutex?
|
120
|
+
@@mutex.synchronize do
|
121
|
+
yield
|
122
|
+
end
|
123
|
+
else
|
124
|
+
yield
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Adapted from Merb
|
129
|
+
# calls a filter chain according to rules.
|
130
|
+
def call_filters(filter_set, context)
|
131
|
+
filter_set.each do |filter|
|
132
|
+
case filter
|
133
|
+
when Symbol, String
|
134
|
+
context.send(filter)
|
135
|
+
when Proc
|
136
|
+
context.instance_eval(&filter)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
:filter_chain_completed
|
87
140
|
end
|
88
141
|
|
89
142
|
end
|
data/lib/sinatra/irb.rb
CHANGED
data/lib/sinatra/options.rb
CHANGED
@@ -7,6 +7,9 @@ module Sinatra
|
|
7
7
|
attr_with_default :port, 4567
|
8
8
|
attr_with_default :environment, :development
|
9
9
|
attr_with_default :console, nil
|
10
|
+
attr_with_default :use_mutex, false
|
11
|
+
|
12
|
+
alias :use_mutex? :use_mutex
|
10
13
|
|
11
14
|
def parse!(args)
|
12
15
|
return if @environment == :test
|
@@ -24,6 +27,9 @@ module Sinatra
|
|
24
27
|
puts opts
|
25
28
|
exit!
|
26
29
|
end
|
30
|
+
opts.on '-X', '--mutex', 'Use mutex lock when attending events' do
|
31
|
+
@use_mutex = true
|
32
|
+
end
|
27
33
|
end.parse!(ARGV)
|
28
34
|
end
|
29
35
|
|
data/lib/sinatra/server.rb
CHANGED
data/sinatra.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Sinatra-0.1.
|
2
|
+
# Gem::Specification for Sinatra-0.1.5
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{sinatra}
|
7
|
-
s.version = "0.1.
|
8
|
-
s.date = %q{2007-10-
|
7
|
+
s.version = "0.1.5"
|
8
|
+
s.date = %q{2007-10-07}
|
9
9
|
s.summary = %q{Sinatra is a classy web-framework dressed in a DSL}
|
10
10
|
s.email = %q{blake.mizerany@gmail.com}
|
11
11
|
s.homepage = %q{http://sinatra.rubyforge.org/}
|
@@ -24,7 +24,6 @@ end
|
|
24
24
|
#
|
25
25
|
# require 'rake/testtask'
|
26
26
|
# require 'ftools'
|
27
|
-
# require 'hoe'
|
28
27
|
#
|
29
28
|
# Version = '0.1.0'
|
30
29
|
#
|
@@ -44,7 +43,7 @@ end
|
|
44
43
|
# p.email = "blake.mizerany@gmail.com"
|
45
44
|
# p.test_pattern = 'test/**/*_test.rb'
|
46
45
|
# p.include_rakefile = true
|
47
|
-
# p.rdoc_pattern = ['README', 'LICENSE']
|
46
|
+
# p.rdoc_pattern = ['README', 'LICENSE'] + Dir.glob('lib/**/*.rb') + Dir.glob('vendor/**/*.rb')
|
48
47
|
# p.docs_host = "bmizerany@rubyforge.org:/var/www/gforge-projects/sinatra/"
|
49
48
|
# end
|
50
49
|
#
|
data/site/index.htm
CHANGED
@@ -85,13 +85,17 @@ end</pre>
|
|
85
85
|
<pre><a href="http://repo.or.cz/w/sinatra.git?a=tree;f=examples;h=fd7513e49762738ad945adbb2e15bb31528b4207;hb=HEAD">here</a></pre>
|
86
86
|
</p>
|
87
87
|
<p>
|
88
|
-
<strong>
|
89
|
-
<pre><a
|
88
|
+
<strong>Docs!</strong><br />
|
89
|
+
<pre><a href="http://sinatra.rubyforge.org/doc/">here</a></pre>
|
90
90
|
</p>
|
91
91
|
<p>
|
92
|
-
<strong>
|
92
|
+
<strong>Can you <a href="http://digg.com/programming/Sinatra_Classy_web_development_dressed_in_a_DSL">digg</a> it cats?</strong><br />
|
93
93
|
<pre><a href="http://sinatra.rubyforge.org/doc/">here</a></pre>
|
94
94
|
</p>
|
95
|
+
<p>
|
96
|
+
<strong>Contribute!</strong><br />
|
97
|
+
<pre><a href="http://repo.or.cz/w/sinatra.git">using git</a></pre>
|
98
|
+
</p>
|
95
99
|
|
96
100
|
</div>
|
97
101
|
</div>
|
data/site/index.html
CHANGED
@@ -85,13 +85,17 @@ end</pre>
|
|
85
85
|
<pre><a href="http://repo.or.cz/w/sinatra.git?a=tree;f=examples;h=fd7513e49762738ad945adbb2e15bb31528b4207;hb=HEAD">here</a></pre>
|
86
86
|
</p>
|
87
87
|
<p>
|
88
|
-
<strong>
|
89
|
-
<pre><a
|
88
|
+
<strong>Docs!</strong><br />
|
89
|
+
<pre><a href="http://sinatra.rubyforge.org/doc/">here</a></pre>
|
90
90
|
</p>
|
91
91
|
<p>
|
92
|
-
<strong>
|
92
|
+
<strong>Can you <a href="http://digg.com/programming/Sinatra_Classy_web_development_dressed_in_a_DSL">digg</a> it cats?</strong><br />
|
93
93
|
<pre><a href="http://sinatra.rubyforge.org/doc/">here</a></pre>
|
94
94
|
</p>
|
95
|
+
<p>
|
96
|
+
<strong>Contribute!</strong><br />
|
97
|
+
<pre><a href="http://repo.or.cz/w/sinatra.git">using git</a></pre>
|
98
|
+
</p>
|
95
99
|
|
96
100
|
</div>
|
97
101
|
</div>
|
data/test/sinatra/event_test.rb
CHANGED
@@ -33,5 +33,14 @@ describe "Event" do
|
|
33
33
|
Sinatra::EventManager.expects(:not_found)
|
34
34
|
Sinatra::EventManager.determine_event(:get, '/asdfsasd')
|
35
35
|
end
|
36
|
+
|
37
|
+
it "should not execute event if halted" do
|
38
|
+
Sinatra::Event.before_filters << lambda { throw :halt, 'whoa!' }
|
39
|
+
event = Sinatra::Event.new(:get, '/') do
|
40
|
+
foo
|
41
|
+
end
|
42
|
+
event.expects(:foo).never
|
43
|
+
get_it('/').should.equal 'whoa!'
|
44
|
+
end
|
36
45
|
|
37
46
|
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: sinatra
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-10-
|
6
|
+
version: 0.1.5
|
7
|
+
date: 2007-10-07 00:00:00 -07:00
|
8
8
|
summary: Sinatra is a classy web-framework dressed in a DSL
|
9
9
|
require_paths:
|
10
10
|
- lib
|