Skip to content

Commit a90b5ad

Browse files
committed
Deprecate flatten()
1 parent 5c4929d commit a90b5ad

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,8 @@ fact('vmware."VRA.version"')
12741274

12751275
#### `flatten`
12761276

1277+
**Deprecated. Puppet 5.5.0 has introduced an inbuilt `flatten` function, that will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).**
1278+
12771279
Flattens deeply nested arrays and returns a single flat array as a result.
12781280

12791281
For example, `flatten(['a', ['b', ['c']]])` returns ['a','b','c'].

lib/puppet/parser/functions/flatten.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ module Puppet::Parser::Functions
1414
DOC
1515
) do |arguments|
1616

17+
function_deprecation([:flatten, 'This method is deprecated, this function is now shipped in puppet in versions 5.5.0 and later.
18+
For more information please see [puppet 5.5.0 release notes|https://puppet.com/docs/puppet/5.5/release_notes.html#new-features].'])
19+
1720
raise(Puppet::ParseError, "flatten(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
1821

1922
array = arguments[0]

spec/functions/flatten_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
describe 'flatten' do
44
it { is_expected.not_to eq(nil) }
5-
it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
6-
it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError) }
7-
it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) }
8-
it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) }
5+
it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0'
6+
it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0'
7+
it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0'
8+
it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0'
99
it { is_expected.to run.with_params([]).and_return([]) }
1010
it { is_expected.to run.with_params(['one']).and_return(['one']) }
1111
it { is_expected.to run.with_params([['one']]).and_return(['one']) }

0 commit comments

Comments
 (0)