Skip to content

Commit

Permalink
fix a few inadvertant bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
brianphillips committed Sep 4, 2013
1 parent dedc0c6 commit 90261c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
13 changes: 7 additions & 6 deletions lib/yard/sinatra.rb
Expand Up @@ -54,14 +54,13 @@ def self.error_handlers
def process
case http_verb
when 'NAMESPACE'
AbstractRouteHandler.uri_prefixes << http_path(true)
AbstractRouteHandler.uri_prefixes << http_path(false)
parse_sinatra_namespace(:scope => :class, :namespace => namespace)
AbstractRouteHandler.uri_prefixes.pop
when 'NOT_FOUND'
register_error_handler(http_verb)
else
path = http_path
register_route(http_verb, path)
register_route(http_verb, http_path)
end
end

Expand Down Expand Up @@ -109,6 +108,7 @@ class RouteHandler < Ruby::Base
handles method_call(:get)
handles method_call(:post)
handles method_call(:put)
handles method_call(:patch)
handles method_call(:delete)
handles method_call(:head)
handles method_call(:not_found)
Expand All @@ -120,7 +120,8 @@ def http_verb

def http_path(include_prefix=true)
path = statement.parameters.first
path = path ? path.last.last.source : ''
path = path ? path.source : ''
path = $1 if path =~ /['"](.*)['"]/
include_prefix ? AbstractRouteHandler.uri_prefix + path : path
end
def parse_sinatra_namespace(opts={})
Expand All @@ -132,7 +133,7 @@ def parse_sinatra_namespace(opts={})
module Legacy
class RouteHandler < Ruby::Legacy::Base
include AbstractRouteHandler
handles /\A(get|post|put|delete|head|not_found|namespace)[\s\(].*/m
handles /\A(get|post|put|patch|delete|head|not_found|namespace)[\s\(].*/m

def http_verb
statement.tokens.first.text.upcase
Expand All @@ -141,7 +142,7 @@ def http_verb
def http_path(include_prefix=true)
path = statement.tokens.find {|t| t.class == YARD::Parser::Ruby::Legacy::RubyToken::TkSTRING }
path = path ? path.text : ''
path = $1 if path =~ /^["'](.+)["']/
path = $1 if path =~ /^["'](.*)["']/
include_prefix ? AbstractRouteHandler.uri_prefix + path : path
end
def parse_sinatra_namespace(opts={})
Expand Down
5 changes: 5 additions & 0 deletions spec/example_app.rb
Expand Up @@ -36,6 +36,11 @@ def settings(some_user)

# nested route
get("/route") {"this is a nested route!"}

namespace "/double" do
# double nested route
get("/route") { }
end
end

end
6 changes: 4 additions & 2 deletions spec/yard/sinatra_spec.rb
Expand Up @@ -7,7 +7,7 @@
end

it "reads sinatra routes" do
YARD::Sinatra.routes.size.should == 7
YARD::Sinatra.routes.size.should == 8
end

it "sets properties correctly" do
Expand Down Expand Up @@ -35,10 +35,12 @@

it "recognizes namespaced routes" do
nested_routes = YARD::Sinatra.routes.find_all {|r| r.http_path[0..6] == "/nested" }
nested_routes.length.should == 2
nested_routes.length.should == 3
nested_routes.each do |route|
if route.http_path == "/nested"
route.docstring.should == "root"
elsif route.http_path == "/nested/double/route"
route.docstring.should == "double nested route"
elsif route.http_path == "/nested/route"
route.docstring.should == "nested route"
else
Expand Down

0 comments on commit 90261c3

Please sign in to comment.