Skip to content

Commit fc18517

Browse files
author
Helen
committed
Merge pull request #599 from hunner/fix_delete
Undo changing delete() to delete regex matches
2 parents 27236a7 + 19752a7 commit fc18517

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ This release provides several new functions, bugfixes, modulesync changes, and s
1414
- Extends `suffix` to support applying a suffix to keys in a hash.
1515
- Apply modulesync changes.
1616
- Add validate_email_address function.
17-
- Add support for regular expressions to delete.
1817

1918
####Bugfixes
2019
- Fixes `fqdn_rand_string` tests, since Puppet 4.4.0 and later have a higher `fqdn_rand` ceiling.

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ Takes a resource reference and an optional hash of attributes. Returns 'true' if
265265

266266
#### `delete`
267267

268-
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.
268+
Deletes all instances of a given element from an array, substring from a string, or key from a hash. 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}. *Type*: rvalue.
269269

270270
#### `delete_at`
271271

lib/puppet/parser/functions/delete.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# delete.rb
33
#
44

5+
# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
6+
57
module Puppet::Parser::Functions
68
newfunction(:delete, :type => :rvalue, :doc => <<-EOS
79
Deletes all instances of a given element from an array, substring from a
@@ -32,7 +34,7 @@ module Puppet::Parser::Functions
3234
Array(arguments[1]).each do |item|
3335
case collection
3436
when Array, Hash
35-
collection.delete_if { |coll_item| coll_item =~ %r{#{item}} }
37+
collection.delete item
3638
when String
3739
collection.gsub! item, ''
3840
else

spec/functions/delete_spec.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
it { is_expected.to run.with_params([], 'two').and_return([]) }
1313
it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
1414
it { is_expected.to run.with_params(['two', 'two'], 'two').and_return([]) }
15-
it { is_expected.to run.with_params(['one', 'two', 'three'], '^t.*').and_return(['one']) }
1615
it { is_expected.to run.with_params(['one', 'two', 'three'], 'four').and_return(['one', 'two', 'three']) }
16+
it { is_expected.to run.with_params(['one', 'two', 'three'], 'e').and_return(['one', 'two', 'three']) }
1717
it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) }
1818
it { is_expected.to run.with_params(['two', 'one', 'two', 'three', 'two'], 'two').and_return(['one', 'three']) }
1919
it { is_expected.to run.with_params(['one', 'two', 'three', 'two'], ['one', 'two']).and_return(['three']) }
@@ -33,7 +33,7 @@
3333
it { is_expected.to run.with_params('barfoobar', ['foo', 'barbar']).and_return('') }
3434
end
3535

36-
describe 'deleting from a hash' do
36+
describe 'deleting from an array' do
3737
it { is_expected.to run.with_params({}, '').and_return({}) }
3838
it { is_expected.to run.with_params({}, 'key').and_return({}) }
3939
it { is_expected.to run.with_params({'key' => 'value'}, 'key').and_return({}) }
@@ -45,10 +45,6 @@
4545
.with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['key1', 'key2']) \
4646
.and_return( {'key3' => 'value3'})
4747
}
48-
it { is_expected.to run \
49-
.with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['^key\d']) \
50-
.and_return({})
51-
}
5248
end
5349

5450
it "should leave the original array intact" do

0 commit comments

Comments
 (0)