Skip to content

Commit 91f0efb

Browse files
committed
Move overriden methods into helpers to prevent breakage in new rails versions
1 parent baf5e6e commit 91f0efb

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

lib/grape-swagger.rb

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def self.setup(options)
8686
header['Access-Control-Request-Method'] = '*'
8787
routes = @@target_class::combined_routes[params[:name]]
8888
routes_array = routes.map do |route|
89-
notes = route.route_notes && @@markdown ? Kramdown::Document.new(route.route_notes.strip_heredoc).to_html : route.route_notes
89+
notes = route.route_notes && @@markdown ? Kramdown::Document.new(strip_heredoc(route.route_notes)).to_html : route.route_notes
9090
http_codes = parse_http_codes route.route_http_codes
9191
operations = {
9292
:notes => notes,
@@ -178,34 +178,22 @@ def parse_http_codes codes
178178
{:code => k, :reason => v}
179179
end
180180
end
181+
182+
def try(*a, &b)
183+
if a.empty? && block_given?
184+
yield self
185+
else
186+
public_send(*a, &b) if respond_to?(a.first)
187+
end
188+
end
189+
190+
def strip_heredoc(string)
191+
indent = string.scan(/^[ \t]*(?=\S)/).min.try(:size) || 0
192+
string.gsub(/^[ \t]{#{indent}}/, '')
193+
end
181194
end
182195
end
183196
end
184197
end
185198
end
186199
end
187-
188-
class Object
189-
##
190-
# @person ? @person.name : nil
191-
# vs
192-
# @person.try(:name)
193-
#
194-
# File activesupport/lib/active_support/core_ext/object/try.rb#L32
195-
def try(*a, &b)
196-
if a.empty? && block_given?
197-
yield self
198-
else
199-
public_send(*a, &b) if respond_to?(a.first)
200-
end
201-
end
202-
end
203-
204-
class String
205-
# strip_heredoc from rails
206-
# File activesupport/lib/active_support/core_ext/string/strip.rb, line 22
207-
def strip_heredoc
208-
indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0
209-
gsub(/^[ \t]{#{indent}}/, '')
210-
end
211-
end

0 commit comments

Comments
 (0)