-
Notifications
You must be signed in to change notification settings - Fork 375
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
Remove dynamic input used in regular expression #2867
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1a51397
Remove dynamic input used in regular expression
marcotc abb314c
Extract backport to is own method
marcotc 48536ab
Merge branch 'master' into remove-dynamic-regex
marcotc ad28578
Add type check
marcotc af6d0d0
Add guard to ensure rbs has non-nil return type
marcotc fdfc987
Move backports
marcotc ba6caf0
Merge branch 'master' into remove-dynamic-regex
marcotc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module Core | ||
module Utils | ||
# Methods from future versions of Ruby implemented in for older rubies. | ||
# | ||
# This helps keep the project using newer APIs for never rubies and | ||
# facilitates cleaning up when support for an older versions of Ruby is removed. | ||
module Backport | ||
# `String` class backports. | ||
module String | ||
module_function | ||
|
||
if ::String.method_defined?(:delete_prefix) | ||
def delete_prefix(string, prefix) | ||
string.delete_prefix(prefix) | ||
end | ||
else | ||
def delete_prefix(string, prefix) | ||
prefix = prefix.to_s | ||
if string.start_with?(prefix) | ||
string[prefix.length..-1] | ||
else | ||
string.dup | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Datadog | ||
module Core | ||
module Utils | ||
module Backport | ||
module String | ||
# This method can't return `nil`, but we use `String#[]` to compute | ||
# its return value and `String#[]` can return `nil` but only in | ||
# scenarios that are impossible for `delete_prefix`. | ||
def self?.delete_prefix: (::String string, ::String prefix) -> ::String? | ||
end | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: As more of a "futurology" comment (e.g. thinking of how this may perhaps evolve in the future), maybe it would make sense to have a more top-level module to contain a bag of backports (e.g.
Datadog::Core::Backport
) or even per-minimum-Ruby-version-to-avoid-the-backport (Datadog::Core::BackportFrom24
) versus having it scoped intoUtils
>String
per-class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the suggestion, could you expand the examples a bit more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
My thinking is -- in this PR we create a
Datadog::Core::Utils::Backport::String
. This seems to be highly specific to, er, strings. So every time we need to do this, we'd need to create backport modules for every class.Furthermore, when eventually we drop support for a few Ruby versions, we'll need to revisit these to figure out which are still needed.
So my suggestion is, why not have a backport module per Ruby version, that would have all backports for all classes there.
E.g. something like:
This way: