@@ -42,7 +42,7 @@ def mount_in(route_set)
4242 end
4343 end
4444 end
45-
45+
4646 def prepare_routes
4747 routes = [ ]
4848 options [ :method ] . each do |method |
@@ -82,7 +82,7 @@ def prepare_path(path)
8282 parts . last << '(.:format)'
8383 Rack ::Mount ::Utils . normalize_path ( parts . join ( '/' ) )
8484 end
85-
85+
8686 def namespace
8787 Rack ::Mount ::Utils . normalize_path ( settings . stack . map { |s | s [ :namespace ] } . join ( '/' ) )
8888 end
@@ -193,13 +193,18 @@ def present(object, options = {})
193193 entity_class ||= ( settings [ :representations ] || { } ) [ potential ]
194194 end
195195
196- if entity_class
196+ root = options . delete ( :root )
197+
198+ representation = if entity_class
197199 embeds = { :env => env }
198200 embeds [ :version ] = env [ 'api.version' ] if env [ 'api.version' ]
199- body entity_class . represent ( object , embeds . merge ( options ) )
201+ entity_class . represent ( object , embeds . merge ( options ) )
200202 else
201- body object
203+ object
202204 end
205+
206+ representation = { root => representation } if root
207+ body representation
203208 end
204209
205210 protected
@@ -220,11 +225,11 @@ def run(env)
220225 def build_middleware
221226 b = Rack ::Builder . new
222227
223- b . use Grape ::Middleware ::Error ,
224- :default_status => settings [ :default_error_status ] || 403 ,
225- :rescue_all => settings [ :rescue_all ] ,
226- :rescued_errors => settings [ :rescued_errors ] ,
227- :format => settings [ :error_format ] || :txt ,
228+ b . use Grape ::Middleware ::Error ,
229+ :default_status => settings [ :default_error_status ] || 403 ,
230+ :rescue_all => settings [ :rescue_all ] ,
231+ :rescued_errors => settings [ :rescued_errors ] ,
232+ :format => settings [ :error_format ] || :txt ,
228233 :rescue_options => settings [ :rescue_options ] ,
229234 :rescue_handlers => settings [ :rescue_handlers ] || { }
230235
0 commit comments