Skip to content

Commit 9416023

Browse files
committed
Address problems with autoloading by searching for constants in instance
1 parent f8c3fee commit 9416023

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/grape/api.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Grape
66
# should subclass this class in order to build an API.
77
class API
88
# Class methods that we want to call on the API rather than on the API object
9-
NON_OVERRIDABLE = %I[define_singleton_method instance_variable_set inspect class is_a? ! kind_of? respond_to?].freeze
9+
NON_OVERRIDABLE = %I[define_singleton_method instance_variable_set inspect class is_a? ! kind_of? respond_to? const_defined? const_missing].freeze
1010

1111
class << self
1212
attr_accessor :base_instance, :instances
@@ -45,6 +45,15 @@ def api.inherited(child_api)
4545
end
4646
end
4747

48+
# Alleviates problems with autoloading by tring to search for the constant
49+
def const_missing(*args)
50+
if base_instance.const_defined?(*args)
51+
base_instance.const_missing(*args)
52+
else
53+
super
54+
end
55+
end
56+
4857
# The remountable class can have a configuration hash to provide some dynamic class-level variables.
4958
# For instance, a descripcion could be done using: `desc configuration[:description]` if it may vary
5059
# depending on where the endpoint is mounted. Use with care, if you find yourself using configuration

0 commit comments

Comments
 (0)