Skip to content

Commit a4cae6d

Browse files
authored
Merge pull request #1830 from myxoh/self_sanity
restores self_sanity Addresses #1829
2 parents 3b95374 + 19852e2 commit a4cae6d

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Fixes
88

99
* Your contribution here.
10+
* [#1830](https://github.com/ruby-grape/grape/pull/1830): Restores self_sanity addresses #1829 - [@myxoh](https://github.com/myxoh).
1011

1112
### 1.2.1 (2018/11/28)
1213

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)