yard-sinatra 0.4.0.1 → 0.5.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/LICENSE +27 -0
- data/README.md +5 -0
- data/lib/yard/sinatra.rb +34 -5
- data/spec/example_app.rb +6 -1
- data/spec/yard/sinatra_spec.rb +14 -1
- metadata +14 -5
data/LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
copyright (c) 2010 Konstantin Haase. All rights reserved.
|
2
|
+
|
3
|
+
Developed by: Konstantin Haase
|
4
|
+
http://github.com/rkh/big_band
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to
|
8
|
+
deal with the Software without restriction, including without limitation the
|
9
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
1. Redistributions of source code must retain the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimers.
|
14
|
+
2. Redistributions in binary form must reproduce the above copyright
|
15
|
+
notice, this list of conditions and the following disclaimers in the
|
16
|
+
documentation and/or other materials provided with the distribution.
|
17
|
+
3. Neither the name of Konstantin Haase, nor the names of other contributors
|
18
|
+
may be used to endorse or promote products derived from this Software without
|
19
|
+
specific prior written permission.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
+
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
26
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
27
|
+
WITH THE SOFTWARE.
|
data/README.md
CHANGED
data/lib/yard/sinatra.rb
CHANGED
@@ -6,6 +6,10 @@ module YARD
|
|
6
6
|
def self.routes
|
7
7
|
YARD::Handlers::Sinatra::AbstractRouteHandler.routes
|
8
8
|
end
|
9
|
+
|
10
|
+
def self.error_handlers
|
11
|
+
YARD::Handlers::Sinatra::AbstractRouteHandler.error_handlers
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
module CodeObjects
|
@@ -37,11 +41,19 @@ module YARD
|
|
37
41
|
@routes ||= []
|
38
42
|
end
|
39
43
|
|
44
|
+
def self.error_handlers
|
45
|
+
@error_handlers ||= []
|
46
|
+
end
|
47
|
+
|
40
48
|
def process
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
49
|
+
case http_verb
|
50
|
+
when 'NOT_FOUND'
|
51
|
+
register_error_handler(http_verb)
|
52
|
+
else
|
53
|
+
path = http_path
|
54
|
+
path = $1 if path =~ /^"(.*)"$/
|
55
|
+
register_route(http_verb, path)
|
56
|
+
end
|
45
57
|
end
|
46
58
|
|
47
59
|
def register_route(verb, path, doc = nil)
|
@@ -63,6 +75,22 @@ module YARD
|
|
63
75
|
AbstractRouteHandler.routes << route
|
64
76
|
yield(route) if block_given?
|
65
77
|
end
|
78
|
+
|
79
|
+
def register_error_handler(verb, doc = nil)
|
80
|
+
error_handler = register CodeObjects::RouteObject.new(namespace, verb, :instance) do |o|
|
81
|
+
o.visibility = "public"
|
82
|
+
o.source = statement.source
|
83
|
+
o.signature = verb
|
84
|
+
o.explicit = true
|
85
|
+
o.scope = scope
|
86
|
+
o.docstring = statement.comments
|
87
|
+
o.http_verb = verb
|
88
|
+
o.real_name = verb
|
89
|
+
o.add_file(parser.file, statement.line)
|
90
|
+
end
|
91
|
+
AbstractRouteHandler.error_handlers << error_handler
|
92
|
+
yield(error_handler) if block_given?
|
93
|
+
end
|
66
94
|
end
|
67
95
|
|
68
96
|
# Route handler for YARD's source parser.
|
@@ -74,6 +102,7 @@ module YARD
|
|
74
102
|
handles method_call(:put)
|
75
103
|
handles method_call(:delete)
|
76
104
|
handles method_call(:head)
|
105
|
+
handles method_call(:not_found)
|
77
106
|
|
78
107
|
def http_verb
|
79
108
|
statement.method_name(true).to_s.upcase
|
@@ -88,7 +117,7 @@ module YARD
|
|
88
117
|
module Legacy
|
89
118
|
class RouteHandler < Ruby::Legacy::Base
|
90
119
|
include AbstractRouteHandler
|
91
|
-
handles /\A(get|post|put|delete|head)[\s\(].*/m
|
120
|
+
handles /\A(get|post|put|delete|head|not_found)[\s\(].*/m
|
92
121
|
|
93
122
|
def http_verb
|
94
123
|
statement.tokens.first.text.upcase
|
data/spec/example_app.rb
CHANGED
@@ -17,7 +17,12 @@ class ExampleApp < Sinatra::Base
|
|
17
17
|
get "/settings" do
|
18
18
|
haml :settings, {}, :settings => settings(current_user)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
|
+
# Error 404 Page Not Found
|
22
|
+
not_found do
|
23
|
+
haml :'404'
|
24
|
+
end
|
25
|
+
|
21
26
|
put("/settings") { }
|
22
27
|
delete("/settings") { }
|
23
28
|
post("/settings") { }
|
data/spec/yard/sinatra_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe YARD::Sinatra do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "reads sinatra routes" do
|
10
|
-
YARD::Sinatra.routes.size.should ==
|
10
|
+
YARD::Sinatra.routes.size.should == 5
|
11
11
|
end
|
12
12
|
|
13
13
|
it "sets properties correctly" do
|
@@ -18,4 +18,17 @@ describe YARD::Sinatra do
|
|
18
18
|
route.docstring.should =~ /Displays a settings page for the current user/ if route.http_verb == "GET"
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
it "reads sinatra error handlers" do
|
23
|
+
YARD::Sinatra.error_handlers.size.should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets error handlers correctly" do
|
27
|
+
YARD::Sinatra.error_handlers.each do |error_handler|
|
28
|
+
%w[NOT_FOUND].should include(error_handler.http_verb)
|
29
|
+
error_handler.file.should =~ /example_app\.rb$/
|
30
|
+
error_handler.docstring.should =~ /Error 404 Page Not Found/ if error_handler.http_verb == "NOT_FOUND"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
21
34
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard-sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
+
- 5
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.4.0.1
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Konstantin Haase
|
@@ -15,16 +15,18 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-07-09 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: yard
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
25
26
|
requirements:
|
26
27
|
- - ~>
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
28
30
|
segments:
|
29
31
|
- 0
|
30
32
|
- 5
|
@@ -36,9 +38,11 @@ dependencies:
|
|
36
38
|
name: rspec
|
37
39
|
prerelease: false
|
38
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
39
42
|
requirements:
|
40
43
|
- - ">="
|
41
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 27
|
42
46
|
segments:
|
43
47
|
- 1
|
44
48
|
- 3
|
@@ -60,6 +64,7 @@ files:
|
|
60
64
|
- spec/example_app.rb
|
61
65
|
- spec/yard/sinatra_spec.rb
|
62
66
|
- README.md
|
67
|
+
- LICENSE
|
63
68
|
has_rdoc: yard
|
64
69
|
homepage: http://github.com/rkh/yard-sinatra
|
65
70
|
licenses: []
|
@@ -70,23 +75,27 @@ rdoc_options: []
|
|
70
75
|
require_paths:
|
71
76
|
- lib
|
72
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
73
79
|
requirements:
|
74
80
|
- - ">="
|
75
81
|
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
76
83
|
segments:
|
77
84
|
- 0
|
78
85
|
version: "0"
|
79
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
80
88
|
requirements:
|
81
89
|
- - ">="
|
82
90
|
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
83
92
|
segments:
|
84
93
|
- 0
|
85
94
|
version: "0"
|
86
95
|
requirements: []
|
87
96
|
|
88
97
|
rubyforge_project:
|
89
|
-
rubygems_version: 1.3.
|
98
|
+
rubygems_version: 1.3.7
|
90
99
|
signing_key:
|
91
100
|
specification_version: 3
|
92
101
|
summary: Displays Sinatra routes (including comments) in YARD output (part of BigBand).
|