@@ -20,12 +20,18 @@ class Instance
2020 end
2121
2222 class << self
23+ extend Forwardable
2324 attr_accessor :base_instance , :instances
2425
25- # Rather than initializing an object of type Grape::API, create an object of type Instance
26- def new ( ...)
27- base_instance . new ( ...)
28- end
26+ delegate_missing_to :base_instance
27+ def_delegators :base_instance , :new , :configuration
28+
29+ # This is the interface point between Rack and Grape; it accepts a request
30+ # from Rack and ultimately returns an array of three values: the status,
31+ # the headers, and the body. See [the rack specification]
32+ # (http://www.rubydoc.info/github/rack/rack/master/file/SPEC) for more.
33+ # NOTE: This will only be called on an API directly mounted on RACK
34+ def_delegators :instance_for_rack , :call , :compile!
2935
3036 # When inherited, will create a list of all instances (times the API was mounted)
3137 # It will listen to the setup required to mount that endpoint, and replicate it on any new instance
@@ -69,15 +75,6 @@ def configure
6975 end
7076 end
7177
72- # This is the interface point between Rack and Grape; it accepts a request
73- # from Rack and ultimately returns an array of three values: the status,
74- # the headers, and the body. See [the rack specification]
75- # (http://www.rubydoc.info/github/rack/rack/master/file/SPEC) for more.
76- # NOTE: This will only be called on an API directly mounted on RACK
77- def call ( ...)
78- instance_for_rack . call ( ...)
79- end
80-
8178 # The remountable class can have a configuration hash to provide some dynamic class-level variables.
8279 # For instance, a description could be done using: `desc configuration[:description]` if it may vary
8380 # depending on where the endpoint is mounted. Use with care, if you find yourself using configuration
@@ -98,27 +95,6 @@ def replay_setup_on(instance)
9895 end
9996 end
10097
101- def respond_to? ( method , include_private = false )
102- super || base_instance . respond_to? ( method , include_private )
103- end
104-
105- def respond_to_missing? ( method , include_private = false )
106- base_instance . respond_to? ( method , include_private )
107- end
108-
109- def method_missing ( method , *args , &block )
110- # If there's a missing method, it may be defined on the base_instance instead.
111- if respond_to_missing? ( method )
112- base_instance . send ( method , *args , &block )
113- else
114- super
115- end
116- end
117-
118- def compile!
119- instance_for_rack . compile! # See API::Instance.compile!
120- end
121-
12298 private
12399
124100 def instance_for_rack
0 commit comments