Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove dependency on ActiveSupport core extensions from Grape instrumentation #706

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def path(endpoint)
version = endpoint.routes.first.options[:version] || ''
prefix = endpoint.routes.first.options[:prefix]&.to_s || ''
parts = [prefix, version] + namespace.split('/') + endpoint.options[:path]
parts.reject { |p| p.blank? || p.eql?('/') }.join('/').prepend('/')
parts.reject { |p| p.nil? || p.empty? || p.eql?('/') }.join('/').prepend('/')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would safe navigation work?

Suggested change
parts.reject { |p| p.nil? || p.empty? || p.eql?('/') }.join('/').prepend('/')
parts.reject { |p| p&.empty? || p.eql?('/') }.join('/').prepend('/')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, no, because p&.empty? returns nil if p is nil, which evaluates to false as a boolean.

3.1.3 :001 > p = nil
 => nil
3.1.3 :002 > p&.empty?
 => nil
3.1.3 :003 > p.nil? || p.empty? || p.eql?('/')
 => true
3.1.3 :004 > p&.empty? || p.eql?('/')
 => false

I guess there are refactor alternatives, but even though it is a bit verbose I thought it was quite readable like this. But of course I'm open to other suggestions 😃

end

def formatter_type(formatter)
Expand Down