-
Notifications
You must be signed in to change notification settings - Fork 582
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
Use reject instead of delete_if #592
Conversation
I think this still includes a change that would break existing functionality. stdlib 4.11:
With this proposed change:
Maybe a new optional parameter would be helpful, so the user could specify if the second parameter should be used literally or as a regular expression. Otherwise all special regex characters would lead to a semantic change anyway. What about this for example:
|
I'm OK with adding a flag to turn on the regex matching, but I'm really confused why your second case is matching. Do we need to explicitly do something like ^expr$? Any ideas on what that flag might look like? An entirely different function even? |
In your previous commit you added Using anchors would somehow solve this problem. But it would also force the user to provide a full matching regex. To remove all entries that contain the letter 'a' somewhere would have to be written as So one solution could be an additional method parameter (e.g. |
Ah, OK. I couldn't find docs on how regex matching return codes worked. We want to do whole-word matching. \b, possibly, from this link. http://stackoverflow.com/questions/4879395/ruby-regex-rejecting-whole-words |
@@ -4,19 +4,22 @@ | |||
it { is_expected.not_to eq(nil) } | |||
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } | |||
it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) } | |||
it { is_expected.to run.with_params([], 'two', 'three').and_raise_error(Puppet::ParseError) } | |||
it { is_expected.to run.with_params([], 'two', 'three') } |
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.
this first block of tests test that the wrong number of arguments raises an error. as you're adding an optional third param, the correct fix here is
it { is_expected.to run.with_params([], 'two', 'three', 'four').and_raise_error(Puppet::ParseError) }
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.
Done.
Hi @jyaworski , a flag seems to be indeed the only way forward here. Good work overall, only a few minor nits around docs and tests. |
@DavidS fixed. Thanks. |
@@ -265,7 +265,7 @@ Takes a resource reference and an optional hash of attributes. Returns 'true' if | |||
|
|||
#### `delete` | |||
|
|||
Deletes all instances of a given element from an array, substring from a string, or key from a hash. Arrays and hashes may also match on regular expressions. For example, `delete(['a','b','c','b'], 'b')` returns ['a','c']; `delete('abracadabra', 'bra')` returns 'acada'. `delete({'a' => 1,'b' => 2,'c' => 3},['b','c'])` returns {'a'=> 1}, `delete(['abf', 'ab', 'ac'], '^ab.*')` returns ['ac']. *Type*: rvalue. | |||
Deletes all instances of a given element from an array, substring from a string, or key from a hash. Arrays and hashes may also match on regular expressions by setting an optional third parameter to a true value. For example, `delete(['a','b','c','b'], 'b')` returns ['a','c']; `delete('abracadabra', 'bra')` returns 'acada'. `delete({'a' => 1,'b' => 2,'c' => 3},['b','c'])` returns {'a'=> 1}, `delete(['abf', 'ab', 'ac'], '^ab.*', true)` returns ['ac']. `delete(['ab', 'b'], 'b')` returns ['ab']. *Type*: rvalue. |
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.
This line is really quite long, can it be broken up?
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.
Done.
We've been discussing this in Triage, and it turned out that this is a backwards incompatible:
passes on the current implementation, but fails on yours, so that's not good, either. |
Ohhh! so the "other" behaviour is not yet released? That then, of course, doesn't make this a breaking change. More investigation required. |
I don't think you need a delete_regex function, because the regex matching will work fine with this 1-line change: It looks like what you want is a delete function that will match on absolute string matching... based on the diff in functionality. This can be accomplished via a new function.. or the user providing a regex that of |
To be clear, this is the functionality I'm trying to do: delete(['lo', 'bond0', 'bond1', 'eth0'], '^bond.*$') => ['lo', 'eth0'] Delete all keys/entries in a hash/array matching a regular expression. |
This looks good @jyaworski! Thanks for making the updates. Can you rebase this and we can push it through. 👍 |
@bmjen done. Thanks. |
Ping @hunner.
@smoeding alerted me to this problem.