Skip to content

Commit 5e96cb0

Browse files
author
Michael Bleigh
committed
Fixes API mounting.
1 parent 10dd57b commit 5e96cb0

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

lib/grape/api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ def inherited(subclass)
350350

351351
def inherit_settings(other_stack)
352352
settings.prepend other_stack
353+
endpoints.each{|e| e.settings.prepend(other_stack)}
353354
end
354355
end
355356

lib/grape/endpoint.rb

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,32 @@ def initialize(settings, options = {}, &block)
2727
end
2828

2929
def mount_in(route_set)
30-
options[:method].each do |method|
31-
options[:path].each do |path|
32-
prepared_path = prepare_path(path)
33-
path = compile_path(path, !options[:app])
34-
regex = Rack::Mount::RegexpWithNamedGroups.new(path)
35-
path_params = regex.named_captures.map { |nc| nc[0] } - [ 'version', 'format' ]
36-
path_params |= (options[:route_options][:params] || [])
37-
request_method = (method.to_s.upcase unless method == :any)
38-
39-
# routes << Route.new(route_options.merge({
40-
# :prefix => prefix,
41-
# :version => settings[:version] ? settings[:version].join('|') : nil,
42-
# :namespace => namespace,
43-
# :method => request_method,
44-
# :path => prepared_path,
45-
# :params => path_params})
46-
# )
47-
48-
route_set.add_route(self,
49-
:path_info => path,
50-
:request_method => request_method
51-
)
30+
if options[:app] && options[:app].respond_to?(:endpoints)
31+
options[:app].endpoints.each{|e| e.mount_in(route_set)}
32+
else
33+
options[:method].each do |method|
34+
options[:path].each do |path|
35+
prepared_path = prepare_path(path)
36+
path = compile_path(path, !options[:app])
37+
regex = Rack::Mount::RegexpWithNamedGroups.new(path)
38+
path_params = regex.named_captures.map { |nc| nc[0] } - [ 'version', 'format' ]
39+
path_params |= (options[:route_options][:params] || [])
40+
request_method = (method.to_s.upcase unless method == :any)
41+
42+
# routes << Route.new(route_options.merge({
43+
# :prefix => prefix,
44+
# :version => settings[:version] ? settings[:version].join('|') : nil,
45+
# :namespace => namespace,
46+
# :method => request_method,
47+
# :path => prepared_path,
48+
# :params => path_params})
49+
# )
50+
51+
route_set.add_route(self,
52+
:path_info => path,
53+
:request_method => request_method
54+
)
55+
end
5256
end
5357
end
5458
end
@@ -80,7 +84,6 @@ def call(env)
8084

8185
def call!(env)
8286
if options[:app]
83-
$stderr.puts env.inspect
8487
options[:app].call(env)
8588
else
8689
builder = build_middleware

spec/grape/api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ class CommunicationError < RuntimeError; end
841841

842842
mount app
843843
end
844-
get '/cool/awesome'
844+
get '/v1/cool/awesome'
845845
last_response.body.should == 'yo'
846846
end
847847
end

0 commit comments

Comments
 (0)