Skip to content

Commit 3de44a3

Browse files
timgaleckasLeFnord
authored andcommitted
GrapeSwagger::DocMethods::Extensions breaks the contract of Kernel#method (#760)
* GrapeSwagger::DocMethods::Extensions breaks the contract of Kernel#method This causes code inspection tools and development workflows to break and may cause developers to choose not to use the gem. * add test for method introspection on GrapeSwagger::DocMethods::Extensions * fix ci lint failure
1 parent d7bf077 commit 3de44a3

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lib/grape-swagger/doc_methods/extensions.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ def extension(part, identifier = :x)
8787
part.select { |x| x == identifier }
8888
end
8989

90-
def method
90+
def method(*args)
91+
# We're shadowing Object.method(:symbol) here so we provide
92+
# a compatibility layer for code that introspects the methods
93+
# of this class
94+
return super if args.size.positive?
95+
9196
@route.request_method.downcase.to_sym
9297
end
9398
end

spec/lib/extensions_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
require 'spec_helper'
44

55
describe GrapeSwagger::DocMethods::Extensions do
6+
context 'it should not break method introspection' do
7+
describe '.method' do
8+
describe 'method introspection' do
9+
specify do
10+
expect(described_class.method(described_class.methods.first)).to be_a(Method)
11+
end
12+
end
13+
end
14+
end
15+
616
describe '#find_definition' do
717
subject { described_class }
818

spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ module TheApi
1010
class TestApi < Grape::API
1111
format :json
1212

13-
documentation = ::Entities::DocumentedHashAndArrayModel.documentation if ::Entities::DocumentedHashAndArrayModel.respond_to?(:documentation)
13+
if ::Entities::DocumentedHashAndArrayModel.respond_to?(:documentation)
14+
documentation = ::Entities::DocumentedHashAndArrayModel.documentation
15+
end
1416

1517
desc 'This returns something'
1618
namespace :arbitrary do

0 commit comments

Comments
 (0)