Skip to content

Commit 532c08d

Browse files
committed
restores self_sanity
1 parent ee23987 commit 532c08d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/grape/api.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ 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?
10-
respond_to? respond_to_missing? const_defined? const_missing parent
11-
parent_name name equal? to_s parents anonymous?].freeze
9+
NON_OVERRIDABLE = Class.new.methods.freeze
1210

1311
class << self
1412
attr_accessor :base_instance, :instances
13+
14+
# Rather than initializing an object of type Grape::API, create an object of type Instance
15+
def new(*args, &block)
16+
base_instance.new(*args, &block)
17+
end
18+
1519
# When inherited, will create a list of all instances (times the API was mounted)
1620
# It will listen to the setup required to mount that endpoint, and replicate it on any new instance
1721
def inherited(api, base_instance_parent = Grape::API::Instance)

spec/grape/api_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3649,4 +3649,22 @@ def before
36493649
end
36503650
end
36513651
end
3652+
3653+
describe 'normal class methods' do
3654+
subject(:grape_api) { Class.new(Grape::API) }
3655+
3656+
before do
3657+
stub_const('MyAPI', grape_api)
3658+
end
3659+
3660+
it 'can find the appropiate name' do
3661+
expect(grape_api.name).to eq 'MyAPI'
3662+
end
3663+
3664+
it 'is equal to itself' do
3665+
expect(grape_api.itself).to eq grape_api
3666+
expect(grape_api).to eq MyAPI
3667+
expect(grape_api.eql?(MyAPI))
3668+
end
3669+
end
36523670
end

0 commit comments

Comments
 (0)