@@ -55,7 +55,7 @@ def initial_setup(base_instance_parent)
55
55
def override_all_methods!
56
56
( base_instance . methods - Class . methods - NON_OVERRIDABLE ) . each do |method_override |
57
57
define_singleton_method ( method_override ) do |*args , &block |
58
- add_setup ( method_override , * args , & block )
58
+ add_setup ( method : method_override , args : args , block : block )
59
59
end
60
60
end
61
61
end
@@ -79,24 +79,24 @@ def configure
79
79
# For instance, a description could be done using: `desc configuration[:description]` if it may vary
80
80
# depending on where the endpoint is mounted. Use with care, if you find yourself using configuration
81
81
# too much, you may actually want to provide a new API rather than remount it.
82
- def mount_instance ( opts = { } )
83
- instance = Class . new ( @base_parent )
84
- instance . configuration = Grape ::Util ::EndpointConfiguration . new ( opts [ : configuration] || { } )
85
- instance . base = self
86
- replay_setup_on ( instance )
87
- instance
82
+ def mount_instance ( configuration : nil )
83
+ Class . new ( @base_parent ) . tap do | instance |
84
+ instance . configuration = Grape ::Util ::EndpointConfiguration . new ( configuration || { } )
85
+ instance . base = self
86
+ replay_setup_on ( instance )
87
+ end
88
88
end
89
89
90
+ private
91
+
90
92
# Replays the set up to produce an API as defined in this class, can be called
91
93
# on classes that inherit from Grape::API
92
94
def replay_setup_on ( instance )
93
95
@setup . each do |setup_step |
94
- replay_step_on ( instance , setup_step )
96
+ replay_step_on ( instance , ** setup_step )
95
97
end
96
98
end
97
99
98
- private
99
-
100
100
def instance_for_rack
101
101
if never_mounted?
102
102
base_instance
@@ -106,34 +106,35 @@ def instance_for_rack
106
106
end
107
107
108
108
# Adds a new stage to the set up require to get a Grape::API up and running
109
- def add_setup ( method , *args , &block )
110
- setup_step = { method : method , args : args , block : block }
111
- @setup += [ setup_step ]
109
+ def add_setup ( step )
110
+ @setup << step
112
111
last_response = nil
113
112
@instances . each do |instance |
114
- last_response = replay_step_on ( instance , setup_step )
113
+ last_response = replay_step_on ( instance , ** step )
115
114
end
116
115
117
- # Updating all previously mounted classes in the case that new methods have been executed.
118
- if method != :mount && @setup . any?
119
- previous_mount_steps = @setup . select { |step | step [ :method ] == :mount }
120
- previous_mount_steps . each do |mount_step |
121
- refresh_mount_step = mount_step . merge ( method : :refresh_mounted_api )
122
- @setup += [ refresh_mount_step ]
123
- @instances . each do |instance |
124
- replay_step_on ( instance , refresh_mount_step )
125
- end
116
+ refresh_mount_step if step [ :method ] != :mount
117
+ last_response
118
+ end
119
+
120
+ # Updating all previously mounted classes in the case that new methods have been executed.
121
+ def refresh_mount_step
122
+ @setup . each do |setup_step |
123
+ next if setup_step [ :method ] != :mount
124
+
125
+ refresh_mount_step = setup_step . merge ( method : :refresh_mounted_api )
126
+ @setup << refresh_mount_step
127
+ @instances . each do |instance |
128
+ replay_step_on ( instance , **refresh_mount_step )
126
129
end
127
130
end
128
-
129
- last_response
130
131
end
131
132
132
- def replay_step_on ( instance , setup_step )
133
- return if skip_immediate_run? ( instance , setup_step [ : args] )
133
+ def replay_step_on ( instance , method : , args : , block : )
134
+ return if skip_immediate_run? ( instance , args )
134
135
135
- args = evaluate_arguments ( instance . configuration , *setup_step [ : args] )
136
- response = instance . send ( setup_step [ : method] , *args , &setup_step [ : block] )
136
+ eval_args = evaluate_arguments ( instance . configuration , *args )
137
+ response = instance . send ( method , *eval_args , &block )
137
138
if skip_immediate_run? ( instance , [ response ] )
138
139
response
139
140
else
0 commit comments