@@ -30,15 +30,6 @@ class << self
3030 # NOTE: This will only be called on an API directly mounted on RACK
3131 def_delegators :base_instance , :new , :configuration , :call , :compile!
3232
33- # When inherited, will create a list of all instances (times the API was mounted)
34- # It will listen to the setup required to mount that endpoint, and replicate it on any new instance
35- def inherited ( api )
36- super
37-
38- api . initial_setup ( self == Grape ::API ? Grape ::API ::Instance : @base_instance )
39- api . override_all_methods!
40- end
41-
4233 # Initialize the instance variables on the remountable class, and the base_instance
4334 # an instance that will be used to create the set up but will not be mounted
4435 def initial_setup ( base_instance_parent )
@@ -51,8 +42,8 @@ def initial_setup(base_instance_parent)
5142 # Redefines all methods so that are forwarded to add_setup and be recorded
5243 def override_all_methods!
5344 ( base_instance . methods - Class . methods - NON_OVERRIDABLE ) . each do |method_override |
54- define_singleton_method ( method_override ) do |*args , &block |
55- add_setup ( method : method_override , args : args , block : block )
45+ define_singleton_method ( method_override ) do |*args , ** kwargs , &block |
46+ add_setup ( method : method_override , args : args , kwargs : kwargs , block : block )
5647 end
5748 end
5849 end
@@ -86,6 +77,15 @@ def mount_instance(configuration: nil)
8677
8778 private
8879
80+ # When inherited, will create a list of all instances (times the API was mounted)
81+ # It will listen to the setup required to mount that endpoint, and replicate it on any new instance
82+ def inherited ( api )
83+ super
84+
85+ api . initial_setup ( self == Grape ::API ? Grape ::API ::Instance : @base_instance )
86+ api . override_all_methods!
87+ end
88+
8989 # Replays the set up to produce an API as defined in this class, can be called
9090 # on classes that inherit from Grape::API
9191 def replay_setup_on ( instance )
@@ -95,7 +95,7 @@ def replay_setup_on(instance)
9595 end
9696
9797 # Adds a new stage to the set up require to get a Grape::API up and running
98- def add_setup ( step )
98+ def add_setup ( ** step )
9999 @setup << step
100100 last_response = nil
101101 @instances . each do |instance |
@@ -119,22 +119,23 @@ def refresh_mount_step
119119 end
120120 end
121121
122- def replay_step_on ( instance , method :, args :, block :)
123- return if skip_immediate_run? ( instance , args )
122+ def replay_step_on ( instance , method :, args :, kwargs : , block :)
123+ return if skip_immediate_run? ( instance , args , kwargs )
124124
125125 eval_args = evaluate_arguments ( instance . configuration , *args )
126- response = instance . __send__ ( method , *eval_args , &block )
127- if skip_immediate_run? ( instance , [ response ] )
126+ eval_kwargs = kwargs . deep_transform_values { |v | evaluate_arguments ( instance . configuration , v ) . first }
127+ response = instance . __send__ ( method , *eval_args , **eval_kwargs , &block )
128+ if skip_immediate_run? ( instance , [ response ] , kwargs )
128129 response
129130 else
130131 evaluate_arguments ( instance . configuration , response ) . first
131132 end
132133 end
133134
134135 # Skips steps that contain arguments to be lazily executed (on re-mount time)
135- def skip_immediate_run? ( instance , args )
136+ def skip_immediate_run? ( instance , args , kwargs )
136137 instance . base_instance? &&
137- ( any_lazy? ( args ) || args . any? { |arg | arg . is_a? ( Hash ) && any_lazy? ( arg . values ) } )
138+ ( any_lazy? ( args ) || args . any? { |arg | arg . is_a? ( Hash ) && any_lazy? ( arg . values ) } || any_lazy? ( kwargs . values ) )
138139 end
139140
140141 def any_lazy? ( args )
0 commit comments